fix(wiki): support orphan count on sqlite
This commit is contained in:
@@ -36,6 +36,13 @@ func (r *wikiPageRepository) wikiCategoryRankOrder() string {
|
||||
return "CASE WHEN COALESCE(jsonb_array_length(category_path), 0) > 0 THEN 0 ELSE 1 END ASC"
|
||||
}
|
||||
|
||||
func (r *wikiPageRepository) wikiEmptyInLinksPredicate() string {
|
||||
if r.db != nil && r.db.Dialector != nil && r.db.Dialector.Name() == "sqlite" {
|
||||
return "(in_links IS NULL OR json_array_length(in_links) = 0)"
|
||||
}
|
||||
return "(in_links IS NULL OR in_links = '[]'::JSONB)"
|
||||
}
|
||||
|
||||
// Create inserts a new wiki page record
|
||||
func (r *wikiPageRepository) Create(ctx context.Context, page *types.WikiPage) error {
|
||||
return r.db.WithContext(ctx).Create(page).Error
|
||||
@@ -1059,7 +1066,7 @@ func (r *wikiPageRepository) CountOrphans(ctx context.Context, kbID string) (int
|
||||
if err := r.db.WithContext(ctx).
|
||||
Model(&types.WikiPage{}).
|
||||
Where("knowledge_base_id = ?", kbID).
|
||||
Where("(in_links IS NULL OR in_links = '[]'::JSONB)").
|
||||
Where(r.wikiEmptyInLinksPredicate()).
|
||||
// Exclude index and log pages as they are naturally root pages
|
||||
Where("page_type NOT IN ?", []string{types.WikiPageTypeIndex, types.WikiPageTypeLog}).
|
||||
Count(&count).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user