|
|
|
@ -432,20 +432,16 @@ class NostrClient { |
|
|
|
const db = await getDB(); |
|
|
|
const db = await getDB(); |
|
|
|
const tx = db.transaction('events', 'readonly'); |
|
|
|
const tx = db.transaction('events', 'readonly'); |
|
|
|
const index = tx.store.index('kind'); |
|
|
|
const index = tx.store.index('kind'); |
|
|
|
const events: NostrEvent[] = []; |
|
|
|
|
|
|
|
let count = 0; |
|
|
|
|
|
|
|
const targetLimit = Math.min(limit, maxEvents); |
|
|
|
const targetLimit = Math.min(limit, maxEvents); |
|
|
|
|
|
|
|
|
|
|
|
// Use cursor to paginate through events
|
|
|
|
// Use getAll() to get all matching events in one operation
|
|
|
|
let cursor = await index.openCursor(IDBKeyRange.only(kind), 'prev'); |
|
|
|
// This keeps the transaction active and avoids cursor iteration issues
|
|
|
|
while (cursor && count < targetLimit) { |
|
|
|
const allEvents = await index.getAll(kind); |
|
|
|
events.push(cursor.value as NostrEvent); |
|
|
|
|
|
|
|
count++; |
|
|
|
|
|
|
|
cursor = await cursor.continue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tx.done; |
|
|
|
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) { |
|
|
|
} catch (error) { |
|
|
|
console.debug('Error getting events by kind from cache:', error); |
|
|
|
console.debug('Error getting events by kind from cache:', error); |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
@ -460,20 +456,16 @@ class NostrClient { |
|
|
|
const db = await getDB(); |
|
|
|
const db = await getDB(); |
|
|
|
const tx = db.transaction('events', 'readonly'); |
|
|
|
const tx = db.transaction('events', 'readonly'); |
|
|
|
const index = tx.store.index('pubkey'); |
|
|
|
const index = tx.store.index('pubkey'); |
|
|
|
const events: NostrEvent[] = []; |
|
|
|
|
|
|
|
let count = 0; |
|
|
|
|
|
|
|
const targetLimit = Math.min(limit, maxEvents); |
|
|
|
const targetLimit = Math.min(limit, maxEvents); |
|
|
|
|
|
|
|
|
|
|
|
// Use cursor to paginate through events
|
|
|
|
// Use getAll() to get all matching events in one operation
|
|
|
|
let cursor = await index.openCursor(IDBKeyRange.only(pubkey), 'prev'); |
|
|
|
// This keeps the transaction active and avoids cursor iteration issues
|
|
|
|
while (cursor && count < targetLimit) { |
|
|
|
const allEvents = await index.getAll(pubkey); |
|
|
|
events.push(cursor.value as NostrEvent); |
|
|
|
|
|
|
|
count++; |
|
|
|
|
|
|
|
cursor = await cursor.continue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tx.done; |
|
|
|
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) { |
|
|
|
} catch (error) { |
|
|
|
console.debug('Error getting events by pubkey from cache:', error); |
|
|
|
console.debug('Error getting events by pubkey from cache:', error); |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
|