Compare commits

..

1 commit

Author SHA1 Message Date
P. Reis
99fd0d2665 Merge branch 'fix-duplicate-url' into 'main'
fix(createWalletSchema): get URL href

See merge request soapbox-pub/ditto!737
2025-05-08 19:25:08 -03:00
2 changed files with 12 additions and 12 deletions

8
deno.lock generated
View file

@ -29,7 +29,6 @@
"jsr:@gleasonator/policy@0.9.3": "0.9.3", "jsr:@gleasonator/policy@0.9.3": "0.9.3",
"jsr:@gleasonator/policy@0.9.4": "0.9.4", "jsr:@gleasonator/policy@0.9.4": "0.9.4",
"jsr:@gleasonator/policy@0.9.5": "0.9.5", "jsr:@gleasonator/policy@0.9.5": "0.9.5",
"jsr:@gleasonator/policy@0.9.6": "0.9.6",
"jsr:@hono/hono@^4.4.6": "4.6.15", "jsr:@hono/hono@^4.4.6": "4.6.15",
"jsr:@negrel/http-ece@0.6.0": "0.6.0", "jsr:@negrel/http-ece@0.6.0": "0.6.0",
"jsr:@negrel/webpush@0.3": "0.3.0", "jsr:@negrel/webpush@0.3": "0.3.0",
@ -327,13 +326,6 @@
"jsr:@nostrify/policies@~0.36.1" "jsr:@nostrify/policies@~0.36.1"
] ]
}, },
"@gleasonator/policy@0.9.6": {
"integrity": "5bbd04f2d986344509547d480b5202e5f42832a4216b5be66c161e638f5e6672",
"dependencies": [
"jsr:@nostrify/nostrify@0.36",
"jsr:@nostrify/policies@~0.36.1"
]
},
"@hono/hono@4.4.6": { "@hono/hono@4.4.6": {
"integrity": "aa557ca9930787ee86b9ca1730691f1ce1c379174c2cb244d5934db2b6314453" "integrity": "aa557ca9930787ee86b9ca1730691f1ce1c379174c2cb244d5934db2b6314453"
}, },

View file

@ -61,6 +61,8 @@ interface DittoPgStoreOpts {
pure?: boolean; pure?: boolean;
/** Chunk size for streaming events. Defaults to 20. */ /** Chunk size for streaming events. Defaults to 20. */
chunkSize?: number; chunkSize?: number;
/** Batch size for fulfilling subscriptions. Defaults to 500. */
batchSize?: number;
/** Max age (in **seconds**) an event can be to be fulfilled to realtime subscribers. */ /** Max age (in **seconds**) an event can be to be fulfilled to realtime subscribers. */
maxAge?: number; maxAge?: number;
/** Whether to listen for events from the database with NOTIFY. */ /** Whether to listen for events from the database with NOTIFY. */
@ -131,9 +133,6 @@ export class DittoPgStore extends NPostgres {
dbEventsCounter.inc({ kind: event.kind }); dbEventsCounter.inc({ kind: event.kind });
if (NKinds.ephemeral(event.kind)) { if (NKinds.ephemeral(event.kind)) {
if (this.encounters.has(event.id)) return;
this.encounters.set(event.id, true);
return await this.fulfill(event); return await this.fulfill(event);
} }
@ -191,7 +190,7 @@ export class DittoPgStore extends NPostgres {
/** Fulfill active subscriptions with this event. */ /** Fulfill active subscriptions with this event. */
protected async fulfill(event: NostrEvent): Promise<void> { protected async fulfill(event: NostrEvent): Promise<void> {
const { maxAge = 60 } = this.opts; const { maxAge = 60, batchSize = 500 } = this.opts;
const now = Math.floor(Date.now() / 1000); const now = Math.floor(Date.now() / 1000);
const age = now - event.created_at; const age = now - event.created_at;
@ -206,12 +205,21 @@ export class DittoPgStore extends NPostgres {
} }
} }
let count = 0;
for (const [subId, { filters, machina }] of this.subs.entries()) { for (const [subId, { filters, machina }] of this.subs.entries()) {
for (const filter of filters) { for (const filter of filters) {
count++;
if (this.matchesFilter(event, filter)) { if (this.matchesFilter(event, filter)) {
machina.push(['EVENT', subId, event]); machina.push(['EVENT', subId, event]);
break; break;
} }
// Yield to event loop.
if (count % batchSize === 0) {
await new Promise((resolve) => setTimeout(resolve, 0));
}
} }
} }
} }