/** * 7z keeps its listing at the end of the last volume, so a split 7z gets a `7z-tail` probe candidate: the last * segment of its highest volume (lib/edge/range_indexer.ts). RAR lists its files in every volume's header, and * its first volume's start (one `archive` candidate) is enough. The live tail reads an upload in pieces while * it's posted, and each piece queues a tail for the last volume it saw so far (TsIgNBewuFbuwWy: 7, for * .002–.008; LOG.md 2026-10-23 (94)); merges bring their members' tails together. Of the given releases' * waiting tails, those below the release's highest volume go. Those of the highest volume stay, all of them: * a piece that saw only part of it queued a segment that isn't its last. */ export async function pruneSevenZipTails(trx: any, releaseIds: (number | string)[]): Promise { if (releaseIds.length === 0) return 0 const result = await trx.rawQuery( `DELETE FROM probe_candidates pc USING ( SELECT id, status, volume, max(volume) OVER (PARTITION BY release_id) AS highest FROM (SELECT id, release_id, status, substring(file from '\\.7z\\.(\\d{1,4})$')::int AS volume FROM probe_candidates WHERE release_id = ANY(?) AND kind = '7z-tail') t ) s WHERE pc.id = s.id AND s.status = 'waiting' AND s.volume < s.highest`, [releaseIds.map(String)] ) return result.rowCount ?? 0 }