| 395 | ...batch.map((r) => r.id) |
| 396 | ); |
| 397 | const keys = batch.filter((r) => r.storage === "r2").map((r) => r.data as string); |
| 398 | if (keys.length > 0) { |
| 399 | try { await this.bucket.delete(keys); } catch (e) { |
| 400 | console.error(`Failed to delete pruned version objects for note ${noteId}:`, e); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // Delete all version data (rows + R2 objects) for a note. Used on permanent delete. |
| 407 | private async deleteAllVersions(noteId: string) { |
| 408 | const rows = this.sql.exec( |
| 409 | "SELECT data FROM note_versions WHERE note_id = ? AND storage = 'r2'", noteId |
| 410 | ).toArray() as any[]; |
| 411 | this.sql.exec("DELETE FROM note_versions WHERE note_id = ?", noteId); |
| 412 | this.sql.exec("DELETE FROM note_branches WHERE note_id = ?", noteId); |