Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -38,7 +38,7 @@ export class InstanceEvent implements IInstanceEvent {
}

get key() {
return `${this.instance}-${this.version}`;
return `${this.instance}-${this.version}-${this.type}-${this.timestamp.getTime()}`;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, it } from 'vitest';

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

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

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

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

const result = deduplicateInstanceEvents(events);

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

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-REGISTERED-1704103200000',
'instance-2-1-REGISTERED-1704103200000',
'instance-3-4-REGISTERED-1704103200000',
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { InstanceEvent } from '@/views/journal/InstanceEvent';

/**
* Removes duplicate instance events from an array based on their key property.
*
* This function filters an array of InstanceEvent objects, keeping only the first occurrence
* of each unique event key. Subsequent events with the same key are filtered out.
*
* @param events - Array of InstanceEvent objects to deduplicate
* @returns A new array containing only unique events (by key), preserving the order of first occurrence
*
* @example
* const events = [
* { key: 'event1', ... },
* { key: 'event2', ... },
* { key: 'event1', ... } // duplicate
* ];
* const unique = deduplicateInstanceEvents(events);
* // Returns first two events only
*/
export function deduplicateInstanceEvents(events: InstanceEvent[]) {
const seen = new Set<string>();
return events.filter((event) => {
if (seen.has(event.key)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@SteKoe is the event key really enough?
It's imperative, in my opinion, that a SBA instance X shows the events recorded by the same instance and not, for example, by the instance Y.
Otherwise there is no traceability anymore and it's, therefore, better to keep things as they're now by enduring the duplicates.

Copy link
Contributor

@SteKoe SteKoe Feb 10, 2026

Choose a reason for hiding this comment

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

Since the backend does not contain the instance name of SBA in the events, this would be a bigger change than just adding deduplication in frontend.

As key is just using instanceId and version, no. We have to respect any value here. Event type as well as timestamp. Otherwise the following events would be reduced, even though they are not the same:

const events = [
  {instance: '123', version: 1, type: "REGISTERED", timestamp: "678"},
  {instance: '123', version: 1, type: "DEREGISTERED", timestamp: "890"},
]

Thanks to the existing tests, I was able to extend the behavior and added some more use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

But then you won't dedup anything I think

return false;
}
seen.add(event.key);
return true;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ import { useDateTimeFormatter } from '@/composables/useDateTimeFormatter';
import subscribing from '@/mixins/subscribing';
import Instance from '@/services/instance';
import { compareBy } from '@/utils/collections';
import {
InstanceEvent,
InstanceEventType,
} from '@/views/journal/InstanceEvent';
import { InstanceEvent } from '@/views/journal/InstanceEvent';
import { InstanceEventType } from '@/views/journal/InstanceEvent';
import JournalTable from '@/views/journal/JournalTable.vue';
import { deduplicateInstanceEvents } from '@/views/journal/deduplicate-events';

export default {
components: { JournalTable, SbaAlert },
Expand All @@ -67,6 +66,7 @@ export default {
data: () => ({
Event,
events: [],
seenEventKeys: new Set(),
listOffset: 0,
showPayload: {},
pageSize: 25,
Expand Down Expand Up @@ -104,7 +104,10 @@ 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.listOffset = events.length - deduplicated.length;
this.error = null;
} catch (error) {
console.warn('Fetching events failed:', error);
Expand All @@ -119,10 +122,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;
}
this.seenEventKeys.add(incomingEvent.key);
this.events = Object.freeze([incomingEvent, ...this.events]);
this.listOffset += 1;
},
error: (error) => {
Expand Down