chore: Add bundled notification for segment membership updates

This commit is contained in:
Dries Augustyns
2026-01-15 19:47:12 +01:00
parent ec402cb9b3
commit 3a16ad3221
2 changed files with 46 additions and 10 deletions
+20 -10
View File
@@ -34,6 +34,10 @@ async function processProjectSegments(projectId: string, projectName?: string):
);
// Process tracked segments with full membership computation (creates events)
let updatedSegmentCount = 0;
let totalAdded = 0;
let totalRemoved = 0;
if (trackedSegments.length > 0) {
for (const segment of trackedSegments) {
try {
@@ -45,22 +49,28 @@ async function processProjectSegments(projectId: string, projectName?: string):
`[SEGMENT-COUNT-WORKER] Segment "${segment.name}": +${result.added} entries, -${result.removed} exits, ${result.total} total members`,
);
// Notify about segment membership update only if there were actual changes
if (projectName && (result.added > 0 || result.removed > 0)) {
await NtfyService.notifySegmentMembershipComputed(
segment.name,
projectName,
projectId,
result.total,
result.added,
result.removed,
);
// Track segments with actual changes for bundled notification
if (result.added > 0 || result.removed > 0) {
updatedSegmentCount++;
totalAdded += result.added;
totalRemoved += result.removed;
}
} catch (error) {
signale.error(`[SEGMENT-COUNT-WORKER] Failed to compute membership for segment ${segment.id}:`, error);
// Continue with other segments
}
}
// Send bundled notification if there were any changes
if (projectName && updatedSegmentCount > 0) {
await NtfyService.notifySegmentMembershipBundled(
projectName,
projectId,
updatedSegmentCount,
totalAdded,
totalRemoved,
);
}
}
// Process non-tracked segments with count-only update (lightweight)
+26
View File
@@ -762,6 +762,32 @@ export class NtfyService {
});
}
/**
* Notify about bundled segment membership updates - LOW priority
* Used when multiple segments are updated in a single processing cycle
*/
public static async notifySegmentMembershipBundled(
projectName: string,
projectId: string,
segmentCount: number,
totalAdded: number,
totalRemoved: number,
): Promise<void> {
const changes: string[] = [];
if (totalAdded > 0) changes.push(`+${totalAdded} added`);
if (totalRemoved > 0) changes.push(`-${totalRemoved} removed`);
const changesText = changes.length > 0 ? ` (${changes.join(', ')})` : '';
const message = `${segmentCount} segment${segmentCount > 1 ? 's' : ''} updated in project "${projectName}" (${projectId})${changesText}`;
await this.send({
title: 'Segment Memberships Updated',
message,
priority: NtfyPriority.LOW,
tags: [NtfyTag.CHART],
});
}
/**
* Notify about segment deleted - MIN priority
*/