♻️ 书源 id 去掉 ext. 前缀,沿用旧内置源数据

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
GarfieldandCopilot committed 2026-11-16 14:07:45 +08:00
1 parent 01e572a5ee
commit f8ad3f73a6
29 files changed
+173 -173

No files matched your search

+29 -29
View File
@@ -46,8 +46,8 @@ require("book.toc_db").read = function(...)
end
do
Assert.is_nil(Toc.read("ext.weread", "missing"))
Assert.is_nil(Toc.read("ext.weread", "broken"))
Assert.is_nil(Toc.read("weread", "missing"))
Assert.is_nil(Toc.read("weread", "broken"))
end
do
@@ -55,19 +55,19 @@ do
store["b2"] = { payload = [[
[{"idx":1,"source_idx":2,"uid":"u1","toc_version":3},{"idx":2,"source_idx":4,"uid":"u2"}]
]], at = now }
Assert.eq(Toc.uid("ext.weread", "b2", 1), "u1")
Assert.eq(Toc.uid("ext.weread", "b2", 2), "u2")
Assert.is_nil(Toc.uid("ext.weread", "b2", 99))
Assert.eq(Toc.index("ext.weread", "b2", "u2"), 2)
Assert.is_nil(Toc.index("ext.weread", "b2", "u9"))
Assert.eq(Toc.sourceIndex("ext.weread", "b2", 1), 2)
Assert.eq(Toc.sourceIndex("ext.weread", "b2", 2), 4)
Assert.is_nil(Toc.sourceIndex("ext.weread", "b2", 99))
Assert.eq(Toc.uid("weread", "b2", 1), "u1")
Assert.eq(Toc.uid("weread", "b2", 2), "u2")
Assert.is_nil(Toc.uid("weread", "b2", 99))
Assert.eq(Toc.index("weread", "b2", "u2"), 2)
Assert.is_nil(Toc.index("weread", "b2", "u9"))
Assert.eq(Toc.sourceIndex("weread", "b2", 1), 2)
Assert.eq(Toc.sourceIndex("weread", "b2", 2), 4)
Assert.is_nil(Toc.sourceIndex("weread", "b2", 99))
end
do
store["old"] = { payload = [[{"idx":1,"source_idx":2,"uid":"old"}]], at = now }
local old = Toc.read("ext.weread", "old")
local old = Toc.read("weread", "old")
Assert.not_nil(old, "旧目录仍须支持离线读取")
Assert.is_false(Toc.isCurrent(old))
end
@@ -76,53 +76,53 @@ do
-- 解码结果进内存:库里的行没了也照样命中,翻页/按章补报不再反复 decode 整份目录。
local before = reads
store["b2"] = nil
require("utils.db").removeIdentity("toc_entries", "ext.weread", "b2")
require("utils.db").removeIdentity("toc_snapshots", "ext.weread", "b2")
Assert.eq(Toc.uid("ext.weread", "b2", 1), "u1")
Assert.eq(Toc.index("ext.weread", "b2", "u2"), 2)
require("utils.db").removeIdentity("toc_entries", "weread", "b2")
require("utils.db").removeIdentity("toc_snapshots", "weread", "b2")
Assert.eq(Toc.uid("weread", "b2", 1), "u1")
Assert.eq(Toc.index("weread", "b2", "u2"), 2)
Assert.eq(reads, before, "命中内存缓存时不得再查库")
-- clear 后回落到库(此时库里已无数据)
Toc.clear()
Assert.is_nil(Toc.read("ext.weread", "b2"))
Assert.is_nil(Toc.read("weread", "b2"))
Assert.is_true(reads > before)
end
do
-- put 落库并直接接管缓存,无需再 decode 一遍
local list = { { idx = 1, uid = "p1" }, { idx = 2, uid = "p2" }, { idx = 3, uid = "p3" } }
Toc.put("ext.weread", "b3", list)
Toc.put("weread", "b3", list)
Assert.is_nil(upserted["b3"], "不再写旧 JSON 列")
local before = reads
Assert.eq(Toc.uid("ext.weread", "b3", 3), "p3")
Assert.eq(Toc.index("ext.weread", "b3", "p2"), 2)
Assert.eq(Toc.uid("weread", "b3", 3), "p3")
Assert.eq(Toc.index("weread", "b3", "p2"), 2)
Assert.eq(reads, before)
-- 章内进度 + 章节序号 → 全书 fraction
Assert.eq(Toc.wholeFraction("ext.weread", "b3", 1, 0), 0)
Assert.eq(Toc.wholeFraction("ext.weread", "b3", 2, 0.5), 0.5)
Assert.eq(Toc.wholeFraction("ext.weread", "b3", 3, 1), 1)
Assert.is_nil(Toc.wholeFraction("ext.weread", "unknown", 1, 0))
Assert.eq(Toc.wholeFraction("weread", "b3", 1, 0), 0)
Assert.eq(Toc.wholeFraction("weread", "b3", 2, 0.5), 0.5)
Assert.eq(Toc.wholeFraction("weread", "b3", 3, 1), 1)
Assert.is_nil(Toc.wholeFraction("weread", "unknown", 1, 0))
local cached_reads = reads
Assert.eq(Toc.uid("ext.weread", "b3", 1), "p1")
Assert.eq(Toc.uid("weread", "b3", 1), "p1")
Assert.eq(reads, cached_reads)
Toc.clear()
Toc.read("ext.weread", "b3")
Toc.read("weread", "b3")
Assert.is_true(reads > cached_reads, "clear 后必须回库")
end
do
local list = { { idx = 1, uid = "failed" } }
writes = false
Assert.is_false(Toc.put("ext.weread", "failed", list))
Assert.is_nil(Toc.read("ext.weread", "failed"))
Assert.is_false(Toc.put("weread", "failed", list))
Assert.is_nil(Toc.read("weread", "failed"))
writes = true
-- 清内存后直接从逐章表恢复。
Toc.clear()
Assert.eq(Toc.read("ext.weread", "b3")[1].uid, "p1")
Assert.eq(Toc.read("weread", "b3")[1].uid, "p1")
now = now + 6 * 60 * 60
Assert.eq(Toc.read("ext.weread", "b3")[1].uid, "p1", "目录不做时间保鲜,旧缓存仍可用")
Assert.eq(Toc.read("weread", "b3")[1].uid, "p1", "目录不做时间保鲜,旧缓存仍可用")
end
os.time = original_time