Sync-Kern:
- internal/sync/hlc.go: Hybrid Logical Clock (wall_ms<<16|counter)
Tick/Now/After, global mutex, strikt monoton + kausal korrekt
- internal/sync/hlc_test.go: Unit-Tests (monoton, kausal, keine Duplikate)
Store-Schicht:
- internal/store/opstore.go: AppendOps idempotent via UNIQUE(client_id,
client_seq) ON CONFLICT DO NOTHING; LWW-Projektion (list_create/
rename/delete, item_add/update/remove) in derselben Transaktion;
PullOps mit Cursor (seq > since, 500er Pages)
- internal/store/liststore.go: CreateList / GetLists / GetList
- internal/store/itemstore.go: GetItems (nicht-gelöschte Items)
- internal/store/suggeststore.go: Search (pg_trgm + LIKE-fallback, 10)
HTTP-Handler:
- internal/httpapi/lists.go: GET/POST /api/lists, GET /api/lists/{id}
- internal/httpapi/ops.go: POST /api/lists/{id}/ops (Push),
GET /api/lists/{id}/ops (Pull ?since=)
- internal/httpapi/suggest.go: GET /api/suggestions?q=
- internal/httpapi/api.go: alle Routen verdrahtet (RequireAuth)
Deployment:
- deploy/Caddyfile.behind-proxy: auto_https off, trusted_proxies
- deploy/Caddyfile: X-Forwarded-Proto hinzugefügt, Kommentar aktualisiert
- deploy/docker-compose.yml: CADDY_HTTP_PORT + CADDY_HTTPS_PORT
- deploy/.env.example: Caddy-Port-Variablen dokumentiert
go build ./... && go vet ./... && go test ./... ✅
HLC-Tests: monoton, kausal, keine Duplikate ✅
AGENTS.md: Phase C vollständig ✅
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
const suggestLimit = 10
|
|
|
|
// SuggestStore provides autocomplete search over aggregated item names.
|
|
type SuggestStore struct {
|
|
pool *pgxpool.Pool
|
|
}
|
|
|
|
// NewSuggestStore creates a SuggestStore backed by the given pool.
|
|
func NewSuggestStore(pool *pgxpool.Pool) *SuggestStore { return &SuggestStore{pool: pool} }
|
|
|
|
// Search returns up to suggestLimit item name suggestions matching q using
|
|
// pg_trgm similarity search. Results are ordered by usage_count DESC so the
|
|
// most-used names appear first.
|
|
func (s *SuggestStore) Search(ctx context.Context, q string) ([]string, error) {
|
|
rows, err := s.pool.Query(ctx, `
|
|
SELECT name
|
|
FROM item_names
|
|
WHERE name % $1 OR name LIKE $2
|
|
ORDER BY usage_count DESC, last_used_at DESC
|
|
LIMIT $3`,
|
|
q, q+"%", suggestLimit,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("suggeststore: search: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var names []string
|
|
for rows.Next() {
|
|
var name string
|
|
if err := rows.Scan(&name); err != nil {
|
|
return nil, fmt.Errorf("suggeststore: scan name: %w", err)
|
|
}
|
|
names = append(names, name)
|
|
}
|
|
return names, rows.Err()
|
|
}
|