diff --git a/src/build/queue.v b/src/build/queue.v index a78e56a..b559552 100644 --- a/src/build/queue.v +++ b/src/build/queue.v @@ -49,13 +49,6 @@ pub fn new_job_queue(default_schedule CronExpression, default_base_image string) } } -// insert_all executes insert for each architecture of the given Target. -pub fn (mut q BuildJobQueue) insert_all(target Target) ! { - for arch in target.arch { - q.insert(target, arch.value)! - } -} - // insert a new target's job into the queue for the given architecture. This // job will then be endlessly rescheduled after being pop'ed, unless removed // explicitely. diff --git a/src/db/logs.v b/src/db/logs.v index 2745467..923dde2 100644 --- a/src/db/logs.v +++ b/src/db/logs.v @@ -84,8 +84,6 @@ pub fn (db &VieterDb) add_build_log(log BuildLog) int { insert log into BuildLog } - // Here, this does work because a log doesn't contain any foreign keys, - // meaning the ORM only has to do a single add inserted_id := db.conn.last_id() as int return inserted_id diff --git a/src/db/targets.v b/src/db/targets.v index 41e56df..a705ebb 100644 --- a/src/db/targets.v +++ b/src/db/targets.v @@ -38,17 +38,14 @@ pub fn (db &VieterDb) get_target(target_id int) ?Target { } // add_target inserts the given target into the database. -pub fn (db &VieterDb) add_target(target Target) int { +pub fn (db &VieterDb) add_target(repo Target) int { sql db.conn { - insert target into Target + insert repo into Target } - // ID of inserted target is the largest id - inserted_target := sql db.conn { - select from Target order by id desc limit 1 - } + inserted_id := db.conn.last_id() as int - return inserted_target.id + return inserted_id } // delete_target deletes the target with the given id from the database. diff --git a/src/server/api_targets.v b/src/server/api_targets.v index dc39d37..16db7e9 100644 --- a/src/server/api_targets.v +++ b/src/server/api_targets.v @@ -12,17 +12,17 @@ fn (mut app App) v1_get_targets() web.Result { filter := models.from_params(app.query) or { return app.json(http.Status.bad_request, new_response('Invalid query parameters.')) } - targets := app.db.get_targets(filter) + repos := app.db.get_targets(filter) - return app.json(.ok, new_data_response(targets)) + return app.json(.ok, new_data_response(repos)) } // v1_get_single_target returns the information for a single target. ['/api/v1/targets/:id'; auth; get] fn (mut app App) v1_get_single_target(id int) web.Result { - target := app.db.get_target(id) or { return app.not_found() } + repo := app.db.get_target(id) or { return app.not_found() } - return app.json(.ok, new_data_response(target)) + return app.json(.ok, new_data_response(repo)) } // v1_post_target creates a new target from the provided query string. @@ -30,27 +30,22 @@ fn (mut app App) v1_get_single_target(id int) web.Result { fn (mut app App) v1_post_target() web.Result { mut params := app.query.clone() - // If a target is created without specifying the arch, we assume it's meant + // If a repo is created without specifying the arch, we assume it's meant // for the default architecture. if 'arch' !in params || params['arch'] == '' { params['arch'] = app.conf.default_arch } - mut new_target := models.from_params(params) or { + new_repo := models.from_params(params) or { return app.json(http.Status.bad_request, new_response(err.msg())) } // Ensure someone doesn't submit an invalid kind - if new_target.kind !in models.valid_kinds { + if new_repo.kind !in models.valid_kinds { return app.json(http.Status.bad_request, new_response('Invalid kind.')) } - id := app.db.add_target(new_target) - new_target.id = id - - // Add the target to the job queue - // TODO return better error here if it's the cron schedule that's incorrect - app.job_queue.insert_all(new_target) or { return app.status(.internal_server_error) } + id := app.db.add_target(new_repo) return app.json(.ok, new_data_response(id)) } @@ -59,7 +54,6 @@ fn (mut app App) v1_post_target() web.Result { ['/api/v1/targets/:id'; auth; delete] fn (mut app App) v1_delete_target(id int) web.Result { app.db.delete_target(id) - app.job_queue.invalidate(id) return app.json(.ok, new_response('')) } @@ -75,10 +69,7 @@ fn (mut app App) v1_patch_target(id int) web.Result { app.db.update_target_archs(id, arch_objs) } - target := app.db.get_target(id) or { return app.status(.internal_server_error) } + repo := app.db.get_target(id) or { return app.status(.internal_server_error) } - app.job_queue.invalidate(id) - app.job_queue.insert_all(target) or { return app.status(.internal_server_error) } - - return app.json(.ok, new_data_response(target)) + return app.json(.ok, new_data_response(repo)) }