Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include screenshot counts in GET/ summary #60

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading