Merge pull request #2733 from PR0M3TH3AN/perf-nostr-service-incremental-updates-3861441146552926280

⚡ Optimize video subscription updates using incremental processing
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-26 13:02:32 -05:00
commit 3bfa2d8a83
2 files changed
+54 -3

No files matched your search

+1
View File
@@ -130,6 +130,7 @@ export class VideoEventBuffer {
}
}
}
updatedVideos.push(video);
continue;
}
+53 -3
View File
@@ -1743,9 +1743,59 @@ export class NostrService {
limit: this.nostrClient.clampVideoRequestLimit(200),
};
const subscription = this.nostrClient.subscribeVideos(
() => {
const updated = this.nostrClient.getActiveVideos();
applyAndNotify(updated, "subscription");
(updatedVideos) => {
if (!Array.isArray(updatedVideos) || !updatedVideos.length) {
return;
}
const activeUpdates = [];
const deletedUpdates = [];
for (const v of updatedVideos) {
if (v.deleted) {
deletedUpdates.push(v);
} else {
activeUpdates.push(v);
}
}
if (deletedUpdates.length > 0) {
const map = this.ensureVideosMap();
for (const v of deletedUpdates) {
if (v.id) {
map.delete(v.id);
}
}
this.markAuthorIndexDirty();
}
const filtered = this.filterVideos(activeUpdates, {
blacklistedEventIds,
isAuthorBlocked,
});
if (filtered.length > 0) {
this.cacheVideos(filtered);
}
if (filtered.length > 0 || deletedUpdates.length > 0) {
// Persist the full list (latest N) from the now-updated cache
const map = this.ensureVideosMap();
const fullList = Array.from(map.values());
fullList.sort((a, b) => {
const aCreated = Number(a?.created_at) || 0;
const bCreated = Number(b?.created_at) || 0;
return bCreated - aCreated;
});
this.emit("videos:updated", {
videos: fullList,
deleted: deletedUpdates,
reason: "subscription",
});
persistFilteredVideos(fullList);
}
},
subscriptionOptions,
);