refactor(wiki): unify category cleaning and push directory listing to SQL
Centralize the wiki category-path normalization (separator/quote cleanup, type-label stripping, dedup, depth cap) into a single types helper shared by the service, repository, and taxonomy layers so stored and queried paths are always cleaned identically and cannot drift. Flatten category_path into fixed category_l1/l2/l3 columns (kept in sync on write) and rewrite ListDistinctCategoryPathsByType to group, count, and paginate directly in cross-dialect SQL, returning the page of child folders plus the total distinct count. This removes the prior full-column scan and in-memory pagination (whose maxPaths cap was effectively dead) and makes Total and later pages correct. Add the level columns + composite index to the wiki migrations and the repo test schema, and cover the SQL grouping/counting/pagination with a new test.
This commit is contained in:
@@ -241,16 +241,7 @@ func remapCategoryPath(current []string, remap map[string][]string) ([]string, b
|
||||
// hierarchy normalizer does (separator/quote cleanup, type-label stripping,
|
||||
// depth cap) so remap keys match what is stored on pages.
|
||||
func cleanCategoryPathParts(parts []string) []string {
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
for _, c := range cleanWikiCategoryPart(part) {
|
||||
out = append(out, c)
|
||||
if len(out) >= 3 {
|
||||
return out
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
return types.CleanWikiCategoryPath(parts)
|
||||
}
|
||||
|
||||
// categoryPathKey builds a stable comparison key for a cleaned category path.
|
||||
|
||||
Reference in New Issue
Block a user