feat(db): implemented iterator over targets

This commit is contained in:
Jef Roosens 2022-12-31 16:10:47 +01:00
parent f8f611f5c5
commit c9edb55abc
Signed by untrusted user: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 130 additions and 66 deletions

View file

@ -11,9 +11,9 @@ fn (mut app App) v1_get_targets() web.Result {
filter := models.from_params<TargetFilter>(app.query) or {
return app.json(.bad_request, new_response('Invalid query parameters.'))
}
targets := app.db.get_targets(filter)
mut iter := app.db.targets(filter)
return app.json(.ok, new_data_response(targets))
return app.json(.ok, new_data_response(iter.collect()))
}
// v1_get_single_target returns the information for a single target.
@ -81,6 +81,3 @@ fn (mut app App) v1_patch_target(id int) web.Result {
return app.json(.ok, new_data_response(target))
}
['/api/v1/targets/search'; auth; get; markused]
fn (mut app App) v1_search_targets()

View file

@ -31,17 +31,8 @@ pub mut:
// init_job_queue populates a fresh job queue with all the targets currently
// stored in the database.
fn (mut app App) init_job_queue() ! {
// Initialize build queues
mut targets := app.db.get_targets(limit: 25)
mut i := u64(0)
for targets.len > 0 {
for target in targets {
app.job_queue.insert_all(target)!
}
i += 25
targets = app.db.get_targets(limit: 25, offset: i)
for target in app.db.targets(limit: 0) {
app.job_queue.insert_all(target)!
}
}