fix(wiki): support orphan count on sqlite

This commit is contained in:
wolfkill
2026-07-23 09:38:56 +08:00
committed by lyingbug
parent 8248752e62
commit f195e0494c
2 changed files with 33 additions and 1 deletions
@@ -332,3 +332,28 @@ func TestListByTypeLight_ClampsLimit(t *testing.T) {
require.NoError(t, err)
assert.LessOrEqual(t, len(clampedEntries), 200)
}
func TestCountOrphans_SQLiteCountsEmptyInLinks(t *testing.T) {
db := setupWikiPagesTestDB(t)
repo := NewWikiPageRepository(db)
ctx := context.Background()
orphan := makeWikiPage("kb-orphans", "entity/orphan", types.WikiPageTypeEntity, types.WikiPageStatusPublished)
orphan.InLinks = types.StringArray{}
linked := makeWikiPage("kb-orphans", "entity/linked", types.WikiPageTypeEntity, types.WikiPageStatusPublished)
linked.InLinks = types.StringArray{"entity/source"}
indexPage := makeWikiPage("kb-orphans", "index", types.WikiPageTypeIndex, types.WikiPageStatusPublished)
indexPage.InLinks = types.StringArray{}
logPage := makeWikiPage("kb-orphans", "log", types.WikiPageTypeLog, types.WikiPageStatusPublished)
logPage.InLinks = types.StringArray{}
otherKB := makeWikiPage("kb-other", "entity/other", types.WikiPageTypeEntity, types.WikiPageStatusPublished)
otherKB.InLinks = types.StringArray{}
for _, p := range []*types.WikiPage{orphan, linked, indexPage, logPage, otherKB} {
require.NoError(t, repo.Create(ctx, p))
}
got, err := repo.CountOrphans(ctx, "kb-orphans")
require.NoError(t, err)
assert.Equal(t, int64(1), got)
}