Files
pages/internal/store/path_completion.go
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

42 lines
1.4 KiB
Go

package store
import (
"context"
"strings"
)
// Completion needs names, never Revision bodies, titles, thumbnails or counts.
// Cap the candidate budget before the caller applies its request's ACL filter.
func (s *Store) ListPathCompletionNames(ctx context.Context, domain, parent, prefix string) ([]BrowserEntry, bool, error) {
base := strings.TrimRight(normalizeBrowserPath(parent), "/") + "/"
rows, err := s.DB.QueryContext(ctx, `WITH relative AS (
SELECT substr(path,length(?)+1) AS rest FROM paths
WHERE domain_uuid=? AND path>=? AND path<? AND path!=?
), children AS (
SELECT CASE WHEN instr(rest,'/')=0 THEN rest ELSE substr(rest,1,instr(rest,'/')-1) END AS name,
MAX(instr(rest,'/')>0) AS is_dir FROM relative WHERE rest!='' GROUP BY 1
) SELECT name,is_dir FROM children
WHERE substr(lower(name),1,length(?))=lower(?) ORDER BY name LIMIT 1001`, base, domain, base, strings.TrimSuffix(base, "/")+"0", parent, prefix, prefix)
if err != nil {
return nil, false, err
}
defer rows.Close()
entries := make([]BrowserEntry, 0)
for rows.Next() {
var entry BrowserEntry
if err := rows.Scan(&entry.Name, &entry.IsDir); err != nil {
return nil, false, err
}
entry.Path = base + entry.Name
entries = append(entries, entry)
}
if err := rows.Err(); err != nil {
return nil, false, err
}
truncated := len(entries) > 1000
if truncated {
entries = entries[:1000]
}
return entries, truncated, nil
}