From 07f7af33b8551bb8d37d0ea297152637194c1da9 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Fri, 6 Feb 2026 00:07:36 +0100 Subject: [PATCH] bug-fix --- public/healthz.json | 4 +-- src/lib/modules/comments/CommentForm.svelte | 15 +++++---- src/lib/services/nostr/nostr-client.ts | 36 ++++++++------------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/public/healthz.json b/public/healthz.json index 119d3cb..d2f0770 100644 --- a/public/healthz.json +++ b/public/healthz.json @@ -2,7 +2,7 @@ "status": "ok", "service": "aitherboard", "version": "0.1.1", - "buildTime": "2026-02-05T22:42:01.031Z", + "buildTime": "2026-02-05T23:07:17.455Z", "gitCommit": "unknown", - "timestamp": 1770331321031 + "timestamp": 1770332837455 } \ No newline at end of file diff --git a/src/lib/modules/comments/CommentForm.svelte b/src/lib/modules/comments/CommentForm.svelte index 429ba7e..045c030 100644 --- a/src/lib/modules/comments/CommentForm.svelte +++ b/src/lib/modules/comments/CommentForm.svelte @@ -168,18 +168,12 @@ } } - // Extract mentions and add p tags - const mentions = await extractMentions(contentWithUrls); - const mentionPubkeys = getMentionPubkeys(mentions); - for (const pubkey of mentionPubkeys) { - tags.push(['p', pubkey]); - } - if (shouldIncludeClientTag()) { tags.push(['client', 'aitherboard']); } // Add file attachments as imeta tags (like jumble) + // Start with content and add file URLs let contentWithUrls = content.trim(); for (const file of uploadedFiles) { // Use imeta tag from upload response (like jumble) @@ -197,6 +191,13 @@ contentWithUrls += `${file.url}\n`; } } + + // Extract mentions and add p tags (after file URLs are added) + const mentions = await extractMentions(contentWithUrls); + const mentionPubkeys = getMentionPubkeys(mentions); + for (const pubkey of mentionPubkeys) { + tags.push(['p', pubkey]); + } console.log(`[CommentForm] Final tags before publishing:`, tags); diff --git a/src/lib/services/nostr/nostr-client.ts b/src/lib/services/nostr/nostr-client.ts index 7b00858..63920a2 100644 --- a/src/lib/services/nostr/nostr-client.ts +++ b/src/lib/services/nostr/nostr-client.ts @@ -432,20 +432,16 @@ class NostrClient { const db = await getDB(); const tx = db.transaction('events', 'readonly'); const index = tx.store.index('kind'); - const events: NostrEvent[] = []; - let count = 0; const targetLimit = Math.min(limit, maxEvents); - // Use cursor to paginate through events - let cursor = await index.openCursor(IDBKeyRange.only(kind), 'prev'); - while (cursor && count < targetLimit) { - events.push(cursor.value as NostrEvent); - count++; - cursor = await cursor.continue(); - } - + // Use getAll() to get all matching events in one operation + // This keeps the transaction active and avoids cursor iteration issues + const allEvents = await index.getAll(kind); await tx.done; - return events; + + // Sort by created_at (newest first) and limit + const sorted = allEvents.sort((a, b) => b.created_at - a.created_at); + return sorted.slice(0, targetLimit); } catch (error) { console.debug('Error getting events by kind from cache:', error); return []; @@ -460,20 +456,16 @@ class NostrClient { const db = await getDB(); const tx = db.transaction('events', 'readonly'); const index = tx.store.index('pubkey'); - const events: NostrEvent[] = []; - let count = 0; const targetLimit = Math.min(limit, maxEvents); - // Use cursor to paginate through events - let cursor = await index.openCursor(IDBKeyRange.only(pubkey), 'prev'); - while (cursor && count < targetLimit) { - events.push(cursor.value as NostrEvent); - count++; - cursor = await cursor.continue(); - } - + // Use getAll() to get all matching events in one operation + // This keeps the transaction active and avoids cursor iteration issues + const allEvents = await index.getAll(pubkey); await tx.done; - return events; + + // Sort by created_at (newest first) and limit + const sorted = allEvents.sort((a, b) => b.created_at - a.created_at); + return sorted.slice(0, targetLimit); } catch (error) { console.debug('Error getting events by pubkey from cache:', error); return [];