MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / Count

Method Count

internal/metadata/store.go:237–263  ·  view source on GitHub ↗

Count returns the number of deduplicated names matching the query (ignoring limit/offset), so the total matches what Search can display.

(ctx context.Context, q SearchQuery)

Source from the content-addressed store, hash-verified

235// Count returns the number of deduplicated names matching the query (ignoring
236// limit/offset), so the total matches what Search can display.
237func (s *Store) Count(ctx context.Context, q SearchQuery) (int, error) {
238 if err := s.Init(ctx); err != nil {
239 return 0, err
240 }
241 db, err := s.open()
242 if err != nil {
243 return 0, err
244 }
245 defer db.Close()
246
247 pattern := "%" + q.Query + "%"
248 args := []any{pattern, pattern, pattern, pattern, pattern}
249 if q.Kind != "" {
250 args = append([]any{q.Kind}, args...)
251 }
252
253 var count int
254 err = db.QueryRowContext(ctx, `
255 SELECT COUNT(*) FROM (
256 SELECT DISTINCT lower(name) FROM metadata_items WHERE `+matchPredicate(q.Kind)+`
257 )`,
258 args...).Scan(&count)
259 if err != nil {
260 return 0, fmt.Errorf("metadata: count: %w", err)
261 }
262 return count, nil
263}
264
265// GetItem returns a single item by kind and install_key.
266func (s *Store) GetItem(ctx context.Context, kind, installKey string) (Item, error) {

Callers 4

TestSearchPaginationFunction · 0.95
SearchPagedMethod · 0.80

Calls 4

InitMethod · 0.95
openMethod · 0.95
matchPredicateFunction · 0.85
QueryRowContextMethod · 0.80

Tested by 3

TestSearchPaginationFunction · 0.76