@@ -268,19 +268,9 @@ func (r *TestCoverageRepository) CountRequirements(params RequirementListParams)
268268 return 0 , nil
269269 }
270270
271- whereClause , havingClause , args := buildRequirementFilters (params )
271+ whereClause , args := buildRequirementFilters (params )
272272
273- query := `
274- SELECT COUNT(*) FROM (
275- SELECT
276- i.id,
277- (` + coverageLinkedCountSubquery + `) as linked_count
278- FROM items i
279- ` + whereClause + `
280- GROUP BY i.id
281- ` + havingClause + `
282- ) sub
283- `
273+ query := `SELECT COUNT(*) FROM items i ` + whereClause
284274
285275 var total int
286276 if err := r .db .QueryRow (query , args ... ).Scan (& total ); err != nil {
@@ -295,7 +285,7 @@ func (r *TestCoverageRepository) ListRequirements(params RequirementListParams)
295285 return []models.RequirementCoverageItem {}, nil
296286 }
297287
298- whereClause , havingClause , args := buildRequirementFilters (params )
288+ whereClause , args := buildRequirementFilters (params )
299289 args = append (args , params .Limit , params .Offset )
300290
301291 query := `
@@ -316,8 +306,6 @@ func (r *TestCoverageRepository) ListRequirements(params RequirementListParams)
316306 JOIN item_types it ON i.item_type_id = it.id
317307 LEFT JOIN statuses s ON i.status_id = s.id
318308 ` + whereClause + `
319- GROUP BY i.id
320- ` + havingClause + `
321309 ORDER BY i.created_at DESC
322310 LIMIT ? OFFSET ?
323311 `
@@ -413,7 +401,7 @@ func coverageWhereArgs(workspaceID int, typeIDs []int) (placeholders string, arg
413401 return strings .Join (slots , "," ), args
414402}
415403
416- func buildRequirementFilters (params RequirementListParams ) (where , having string , args []any ) {
404+ func buildRequirementFilters (params RequirementListParams ) (where string , args []any ) {
417405 placeholders , filterArgs := coverageWhereArgs (params .WorkspaceID , params .TypeIDs )
418406 args = filterArgs
419407 where = "WHERE i.workspace_id = ? AND i.item_type_id IN (" + placeholders + ")"
@@ -425,9 +413,9 @@ func buildRequirementFilters(params RequirementListParams) (where, having string
425413
426414 switch params .CoveredFilter {
427415 case "true" :
428- having = " HAVING linked_count > 0"
416+ where + = " AND (" + coverageLinkedCountSubquery + ") > 0"
429417 case "false" :
430- having = " HAVING linked_count = 0"
418+ where + = " AND (" + coverageLinkedCountSubquery + ") = 0"
431419 }
432- return where , having , args
420+ return where , args
433421}
0 commit comments