Skip to content

Commit

Permalink
include screenshot counts in GET/ summary (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubfaouzi authored May 11, 2024
1 parent 3b7f8c2 commit e0b3e08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions db/file-summary.n1ql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SELECT
},
"pe_meta": f.pe.meta,
"default_behavior_id": f.default_behavior_id,
"screenshots_count": f.screenshots_count,
"liked": CASE WHEN ARRAY_LENGTH(user_likes) = 0 THEN false
ELSE ARRAY_BINARY_SEARCH(ARRAY_SORT((user_likes)[0]), f.sha256) >= 0 END
}.*
Expand Down
21 changes: 20 additions & 1 deletion internal/behavior/repostitory.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,28 @@ func (r repository) CountArtifacts(ctx context.Context, id string) (int, error)
var statement string
params := make(map[string]interface{}, 1)
params["id"] = id
statement =

filters, ok := ctx.Value(filtersKey).(map[string][]string)
if ok {
statement =
"SELECT RAW COUNT(artifacts) AS count FROM `" + r.db.Bucket.Name() + "` d" +
" USE KEYS $id UNNEST d.artifacts as artifacts"
i := 0
for k, v := range filters {
if i == 0 {
statement += " WHERE"
} else {
statement += " AND"
}
i++
statement += fmt.Sprintf(" artifacts.%s IN $%s", k, k)
params[k] = v
}
} else {
statement =
"SELECT RAW ARRAY_LENGTH(d.artifacts) AS count FROM `" + r.db.Bucket.Name() + "` d" +
" USE KEYS $id"
}

err := r.db.Count(ctx, statement, params, &count)
return count, err
Expand Down

0 comments on commit e0b3e08

Please sign in to comment.