Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

@@ -125,6 +125,25 @@ actor ArchiveLibraryCatalog {
return try rows.map(document)
}
func document(id: String) throws -> ArchiveDocument? {
guard Self.isSHA(id) else { return nil }
return try database().rows("SELECT * FROM document WHERE sha256=? LIMIT 1", [id]).first.map(document)
}
/// Locate the exact title in the same deterministic order used by Browse.
/// Deep links must not depend on the title happening to be in its first batch.
func browseOffset(documentID: String, collection: String?, batchSize: Int) throws -> Int? {
guard (1...50).contains(batchSize), let target = try document(id: documentID) else { return nil }
let filter = try scope(collection)
let rows = try database().rows("""
SELECT count(*) AS amount FROM document d WHERE 1=1 \(filter.sql)
AND (d.title COLLATE NOCASE < ? COLLATE NOCASE OR
(d.title COLLATE NOCASE = ? COLLATE NOCASE AND d.sha256 < ?))
""", filter.values + [target.title, target.title, target.id])
guard let amount = rows.first?["amount"].flatMap(Int.init), amount <= 250_000 else { return nil }
return (amount / batchSize) * batchSize
}
private static let compounds = ["module directory", "width 80", "width 40", "disk basic", "extended basic"]
private func match(_ query: String) throws -> String {