MCPcopy Index your code
hub / github.com/git-bug/git-bug / Query

Method Query

cache/bug_subcache.go:113–184  ·  view source on GitHub ↗

Query return the id of all Bug matching the given Query

(q *query.Query)

Source from the content-addressed store, hash-verified

111
112// Query return the id of all Bug matching the given Query
113func (c *RepoCacheBug) Query(q *query.Query) ([]entity.Id, error) {
114 c.mu.RLock()
115 defer c.mu.RUnlock()
116
117 if q == nil {
118 return c.AllIds(), nil
119 }
120
121 matcher := compileMatcher(q.Filters)
122
123 var filtered []*BugExcerpt
124 var foundBySearch map[entity.Id]*BugExcerpt
125
126 if q.Search != nil {
127 foundBySearch = map[entity.Id]*BugExcerpt{}
128
129 index, err := c.repo.GetIndex("bugs")
130 if err != nil {
131 return nil, err
132 }
133
134 res, err := index.Search(q.Search)
135 if err != nil {
136 return nil, err
137 }
138
139 for _, hit := range res {
140 id := entity.Id(hit)
141 foundBySearch[id] = c.excerpts[id]
142 }
143 } else {
144 foundBySearch = c.excerpts
145 }
146
147 for _, excerpt := range foundBySearch {
148 if matcher.Match(excerpt, c.resolvers()) {
149 filtered = append(filtered, excerpt)
150 }
151 }
152
153 var sorter sort.Interface
154
155 switch q.OrderBy {
156 case query.OrderById:
157 sorter = BugsById(filtered)
158 case query.OrderByCreation:
159 sorter = BugsByCreationTime(filtered)
160 case query.OrderByEdit:
161 sorter = BugsByEditTime(filtered)
162 default:
163 return nil, errors.New("missing sort type")
164 }
165
166 switch q.OrderDirection {
167 case query.OrderAscending:
168 // Nothing to do
169 case query.OrderDescending:
170 sorter = sort.Reverse(sorter)

Callers

nothing calls this directly

Calls 11

IdTypeAlias · 0.92
compileMatcherFunction · 0.85
BugsByIdTypeAlias · 0.85
AllIdsMethod · 0.80
BugsByCreationTimeTypeAlias · 0.70
BugsByEditTimeTypeAlias · 0.70
GetIndexMethod · 0.65
SearchMethod · 0.65
IdMethod · 0.65
MatchMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected