package db import "context" // IntentReferenceIDs follows the claimed intent's own incoming references. The // global graph visualization limit must never truncate execution handovers. func (s *ExplorationStore) IntentReferenceIDs(ctx context.Context, intent, before int64, limit int) (ids []int64, total int, more bool, err error) { if limit <= 0 { limit = 16 } if limit > 50 { limit = 50 } const where = `exploration_id=$1 AND dst_id=$2 AND rel='derived_from'` err = s.db.QueryRowContext(ctx, `SELECT count(*) FROM exploration_edges WHERE `+where, s.expID, intent).Scan(&total) if err != nil { return } rows, e := s.db.QueryContext(ctx, `SELECT src_id FROM exploration_edges WHERE `+where+` AND ($3<=0 OR src_id<$3) ORDER BY src_id DESC LIMIT $4`, s.expID, intent, before, limit+1) if e != nil { err = e return } defer rows.Close() for rows.Next() { var id int64 if err = rows.Scan(&id); err != nil { return } ids = append(ids, id) } if err = rows.Err(); err != nil { return } more = len(ids) > limit if more { ids = ids[:limit] } return }