mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-21 13:20:13 +00:00
fix(storage): optimize attachment retrieval by batching cipher IDs to improve performance
This commit is contained in:
@@ -471,10 +471,15 @@ export class StorageService {
|
|||||||
const grouped = new Map<string, Attachment[]>();
|
const grouped = new Map<string, Attachment[]>();
|
||||||
if (cipherIds.length === 0) return grouped;
|
if (cipherIds.length === 0) return grouped;
|
||||||
|
|
||||||
const placeholders = cipherIds.map(() => '?').join(',');
|
const uniqueCipherIds = [...new Set(cipherIds)];
|
||||||
|
const chunkSize = LIMITS.performance.bulkMoveChunkSize;
|
||||||
|
|
||||||
|
for (let i = 0; i < uniqueCipherIds.length; i += chunkSize) {
|
||||||
|
const chunk = uniqueCipherIds.slice(i, i + chunkSize);
|
||||||
|
const placeholders = chunk.map(() => '?').join(',');
|
||||||
const res = await this.db
|
const res = await this.db
|
||||||
.prepare(`SELECT id, cipher_id, file_name, size, size_name, key FROM attachments WHERE cipher_id IN (${placeholders})`)
|
.prepare(`SELECT id, cipher_id, file_name, size, size_name, key FROM attachments WHERE cipher_id IN (${placeholders})`)
|
||||||
.bind(...cipherIds)
|
.bind(...chunk)
|
||||||
.all<any>();
|
.all<any>();
|
||||||
|
|
||||||
for (const row of (res.results || [])) {
|
for (const row of (res.results || [])) {
|
||||||
@@ -493,6 +498,7 @@ export class StorageService {
|
|||||||
grouped.set(item.cipherId, [item]);
|
grouped.set(item.cipherId, [item]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return grouped;
|
return grouped;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user