Files
pages/internal/store/public_periodicals.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

45 lines
1.3 KiB
Go

package store
import (
"context"
"strings"
"time"
)
// A registered title is public presentation metadata iff its Page has a live
// publication grant. Other registration fields are deliberately not selected.
func (s *Store) PublicPeriodicalTitles(ctx context.Context, domain, kind string, pages []PublishedNavigationPage) (map[string]string, error) {
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
titles := map[string]string{}
paths := map[string][]string{}
args := []any{domain, kind}
for _, p := range pages {
if _, exists := paths[p.Revision.ObjectUUID]; !exists {
args = append(args, p.Revision.ObjectUUID)
}
paths[p.Revision.ObjectUUID] = append(paths[p.Revision.ObjectUUID], p.Path)
}
if len(paths) == 0 {
return titles, nil
}
rows, err := s.DB.QueryContext(ctx, `SELECT page_uuid,title FROM periodical_entries WHERE domain_uuid=? AND kind=? AND page_uuid IN (`+strings.TrimSuffix(strings.Repeat("?,", len(paths)), ",")+`)`, args...)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var object, title string
if err := rows.Scan(&object, &title); err != nil {
return nil, err
}
for _, path := range paths[object] {
titles[path] = title
}
if len(titles) > MaxNavigationEntries {
return nil, ErrNavigationBudget
}
}
return titles, rows.Err()
}