mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Merge branch 'unstable' into ai/performance-events-cache-dirty-tracking-5412442767823742174
This commit is contained in:
6 files changed
+100
-11
No files matched your search
+37
-1
@@ -747,6 +747,7 @@ class EventsCacheStore {
|
||||
let eventDeletes = 0;
|
||||
let tombstoneWrites = 0;
|
||||
let tombstoneDeletes = 0;
|
||||
let skipped = 0;
|
||||
|
||||
// Optimization: If dirtyEventIds is provided, only check those events.
|
||||
// Otherwise, iterate over all events in the payload.
|
||||
@@ -759,6 +760,16 @@ class EventsCacheStore {
|
||||
if (!id || !video) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
dirtyEventIds &&
|
||||
!dirtyEventIds.has(id) &&
|
||||
this.persistedEventFingerprints.has(id)
|
||||
) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const fingerprint = this.computeEventFingerprint(video);
|
||||
const prevFingerprint = this.persistedEventFingerprints.get(id);
|
||||
if (prevFingerprint === fingerprint) {
|
||||
@@ -797,6 +808,16 @@ class EventsCacheStore {
|
||||
if (!key || !Number.isFinite(timestamp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
dirtyTombstones &&
|
||||
!dirtyTombstones.has(key) &&
|
||||
this.persistedTombstoneFingerprints.has(key)
|
||||
) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const fingerprint = this.computeTombstoneFingerprint(timestamp);
|
||||
const prevFingerprint = this.persistedTombstoneFingerprints.get(key);
|
||||
if (prevFingerprint === fingerprint) {
|
||||
@@ -834,6 +855,7 @@ class EventsCacheStore {
|
||||
eventDeletes,
|
||||
tombstoneWrites,
|
||||
tombstoneDeletes,
|
||||
skipped,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1272,6 +1294,8 @@ export class NostrClient {
|
||||
* @public
|
||||
*/
|
||||
this.tombstones = new Map();
|
||||
this.dirtyEventIds = new Set();
|
||||
this.dirtyTombstones = new Set();
|
||||
|
||||
this.rootCreatedAtByRoot = new Map();
|
||||
|
||||
@@ -3975,6 +3999,9 @@ export class NostrClient {
|
||||
);
|
||||
}
|
||||
|
||||
this.dirtyEventIds.clear();
|
||||
this.dirtyTombstones.clear();
|
||||
|
||||
return this.allEvents.size > 0;
|
||||
}
|
||||
|
||||
@@ -7533,6 +7560,9 @@ export class NostrClient {
|
||||
let summary = null;
|
||||
let target = "localStorage";
|
||||
|
||||
const dirtyEventsSnapshot = new Set(this.dirtyEventIds);
|
||||
const dirtyTombstonesSnapshot = new Set(this.dirtyTombstones);
|
||||
|
||||
try {
|
||||
summary = await this.eventsCacheStore.persistSnapshot(
|
||||
payload,
|
||||
@@ -7541,6 +7571,12 @@ export class NostrClient {
|
||||
);
|
||||
if (summary?.persisted) {
|
||||
target = "IndexedDB";
|
||||
for (const id of dirtyEventsSnapshot) {
|
||||
this.dirtyEventIds.delete(id);
|
||||
}
|
||||
for (const key of dirtyTombstonesSnapshot) {
|
||||
this.dirtyTombstones.delete(key);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
devLogger.warn(
|
||||
@@ -7562,7 +7598,7 @@ export class NostrClient {
|
||||
|
||||
const durationMs = Date.now() - startedAt;
|
||||
devLogger.log(
|
||||
`[nostr] Cached events persisted via ${target} (reason=${reason}, duration=${durationMs}ms, events+${summary?.eventWrites ?? 0}/-${summary?.eventDeletes ?? 0}, tombstones+${summary?.tombstoneWrites ?? 0}/-${summary?.tombstoneDeletes ?? 0})`,
|
||||
`[nostr] Cached events persisted via ${target} (reason=${reason}, duration=${durationMs}ms, events+${summary?.eventWrites ?? 0}/-${summary?.eventDeletes ?? 0}, tombstones+${summary?.tombstoneWrites ?? 0}/-${summary?.tombstoneDeletes ?? 0}, skipped=${summary?.skipped ?? 0})`,
|
||||
);
|
||||
|
||||
return summary?.persisted;
|
||||
|
||||
+17
-3
@@ -207,6 +207,11 @@ export class TorrentClient {
|
||||
magnetURI,
|
||||
{ timeoutMs = 8000, maxWebConns = 2, polls = 2, urlList = [] } = {}
|
||||
) {
|
||||
// Debug log for CI investigation
|
||||
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
|
||||
console.log(`[probePeers] magnetURI=${magnetURI?.substring(0, 20)}... urlList=${JSON.stringify(urlList)}`);
|
||||
}
|
||||
|
||||
const magnet = stripXsParameter(magnetURI);
|
||||
|
||||
if (!magnet) {
|
||||
@@ -228,6 +233,10 @@ export class TorrentClient {
|
||||
const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed=");
|
||||
const hasExplicitWebSeed = Array.isArray(urlList) && urlList.length > 0;
|
||||
|
||||
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
|
||||
console.log(`[probePeers] hasMagnetWebSeed=${hasMagnetWebSeed} hasExplicitWebSeed=${hasExplicitWebSeed}`);
|
||||
}
|
||||
|
||||
if (hasExplicitWebSeed) {
|
||||
const wsParams = urlList
|
||||
.map((url) => `ws=${encodeURIComponent(url)}`)
|
||||
@@ -336,6 +345,9 @@ export class TorrentClient {
|
||||
}
|
||||
torrent = client.add(augmentedMagnet, addOptions);
|
||||
} catch (err) {
|
||||
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
|
||||
console.log(`[probePeers] client.add threw:`, err);
|
||||
}
|
||||
finalize({
|
||||
reason: "error",
|
||||
error: toError(err),
|
||||
@@ -403,9 +415,11 @@ export class TorrentClient {
|
||||
|
||||
if (safeTimeout > 0) {
|
||||
timeoutId = setTimeout(() => {
|
||||
const counts = getPeerCounts();
|
||||
const webseedOnly = counts.regularPeers === 0 && counts.webSeeds > 0;
|
||||
const peers = Math.max(0, counts.totalPeers);
|
||||
const peers = Math.max(0, Math.floor(normalizeNumber(torrent?.numPeers, 0)));
|
||||
const webseedOnly = peers === 0 && hasWebSeed;
|
||||
if (typeof process !== "undefined" && process.env.NODE_ENV === "test" && !webseedOnly && hasWebSeed) {
|
||||
console.log(`[probePeers:timeout] logic check: peers=${peers} hasWebSeed=${hasWebSeed} webseedOnly=${webseedOnly}`);
|
||||
}
|
||||
finalize({
|
||||
healthy: webseedOnly,
|
||||
peers,
|
||||
|
||||
Reference in new issue
Block a user