fix for gifs auto-catigorisation

This commit is contained in:
onysd 2026-08-24 23:26:57 +03:00
parent 0321c196bd
commit 58a0aed4f3
3 changed files with 23 additions and 11 deletions

View file

@ -19,9 +19,14 @@ type GifCatalogStore interface {
// Always false for an empty filename (that's the panel-upload sentinel,
// never a real seed match).
HasGifCatalogSourceFilename(ctx context.Context, filename string) (bool, error)
// ListGifCatalog returns every entry ordered by (sort_order, id).
// onlyEnabled=true is what @gif serves; the admin panel lists everything.
ListGifCatalog(ctx context.Context, onlyEnabled bool) ([]domain.GifCatalogEntry, error)
// ListGifCatalog returns entries ordered by (sort_order, id).
// onlyEnabled=true is what @gif serves. limit>0 caps the result (@gif's
// live-serving path passes domain.MaxGifCatalogEntries -- the real TL-level
// cap one inline response can carry); limit<=0 means unbounded, which is
// what the admin panel and bulk operations like auto-categorize need --
// capping those at the same 50 the client renders per response would
// silently only ever touch the first page of a real catalog.
ListGifCatalog(ctx context.Context, onlyEnabled bool, limit int) ([]domain.GifCatalogEntry, error)
// SetGifCatalogEnabled toggles whether an entry is served. changed=false
// if the id doesn't exist.
SetGifCatalogEnabled(ctx context.Context, id int64, enabled bool) (bool, error)

View file

@ -48,13 +48,19 @@ func (s *GifCatalogStore) HasGifCatalogSourceFilename(ctx context.Context, filen
return exists, nil
}
func (s *GifCatalogStore) ListGifCatalog(ctx context.Context, onlyEnabled bool) ([]domain.GifCatalogEntry, error) {
func (s *GifCatalogStore) ListGifCatalog(ctx context.Context, onlyEnabled bool, limit int) ([]domain.GifCatalogEntry, error) {
// Postgres treats LIMIT NULL as "no limit" -- a nil *int parameter gets
// there without a second query string for the unbounded (admin) case.
var limitParam *int
if limit > 0 {
limitParam = &limit
}
rows, err := s.db.Query(ctx, `
SELECT id, title, document_id, enabled, sort_order, created_by, created_at, updated_at, source_filename, category
FROM gif_catalog
WHERE NOT $1 OR enabled
ORDER BY sort_order, id
LIMIT `+fmt.Sprint(domain.MaxGifCatalogEntries), onlyEnabled)
LIMIT $2`, onlyEnabled, limitParam)
if err != nil {
return nil, fmt.Errorf("list gif catalog: %w", err)
}