forked from vieter-v/vieter
feat(db): implemented iterator over targets
This commit is contained in:
parent
f8f611f5c5
commit
c9edb55abc
5 changed files with 130 additions and 66 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue