Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*!
* Copyright 2014-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, expect, it } from 'vitest';

import { InstanceEvent } from '@/views/journal/InstanceEvent';

import { deduplicateInstanceEvents } from './deduplicate-events';

const createEvent = (instance: string, version: number) =>
new InstanceEvent({
instance,
version,
type: 'REGISTERED',
timestamp: '2024-01-01T10:00:00Z',
registration: { name: instance },
});

describe('deduplicateInstanceEvents', () => {
it('removes events with identical instance and version', () => {
const events = [
createEvent('instance-1', 1),
createEvent('instance-1', 1),
createEvent('instance-2', 3),
createEvent('instance-2', 3),
createEvent('instance-3', 2),
];

const result = deduplicateInstanceEvents(events);

expect(result).toHaveLength(3);
expect(result.map((event) => event.key)).toEqual([
'instance-1-1',
'instance-2-3',
'instance-3-2',
]);
});

it('preserves the order of the first occurrences', () => {
const events = [
createEvent('instance-1', 2),
createEvent('instance-2', 1),
createEvent('instance-1', 2),
createEvent('instance-3', 4),
];

const result = deduplicateInstanceEvents(events);

expect(result.map((event) => event.key)).toEqual([
'instance-1-2',
'instance-2-1',
'instance-3-4',
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2014-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InstanceEvent } from '@/views/journal/InstanceEvent';

export function deduplicateInstanceEvents(events: InstanceEvent[]) {
const seen = new Set<string>();
return events.filter((event) => {
if (seen.has(event.key)) {
return false;
}
seen.add(event.key);
return true;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import subscribing from '@/mixins/subscribing';
import Instance from '@/services/instance';
import { compareBy } from '@/utils/collections';
import { InstanceEvent } from '@/views/journal/InstanceEvent';
import { deduplicateInstanceEvents } from '@/views/journal/deduplicate-events';
import JournalTable from '@/views/journal/JournalTable.vue';

export default {
Expand All @@ -64,6 +65,7 @@ export default {
data: () => ({
Event,
events: [],
seenEventKeys: new Set(),
listOffset: 0,
showPayload: {},
pageSize: 25,
Expand Down Expand Up @@ -101,7 +103,9 @@ export default {
.reverse()
.map((e) => new InstanceEvent(e));

this.events = Object.freeze(events);
const deduplicated = deduplicateInstanceEvents(events);
this.seenEventKeys = new Set(deduplicated.map((event) => event.key));
this.events = Object.freeze(deduplicated);
this.error = null;
} catch (error) {
console.warn('Fetching events failed:', error);
Expand All @@ -116,10 +120,12 @@ export default {
return Instance.getEventStream().subscribe({
next: (message) => {
this.error = null;
this.events = Object.freeze([
new InstanceEvent(message.data),
...this.events,
]);
const incomingEvent = new InstanceEvent(message.data);
if (this.seenEventKeys.has(incomingEvent.key)) {
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be wrong here because then listOffset doesn't get updated properly.
@SteKoe @ulischulte your thoughts on this?

}
this.seenEventKeys.add(incomingEvent.key);
this.events = Object.freeze([incomingEvent, ...this.events]);
this.listOffset += 1;
},
error: (error) => {
Expand Down