aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/git-branch.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix-data-service/model/git-branch.scm')
-rw-r--r--guix-data-service/model/git-branch.scm136
1 files changed, 82 insertions, 54 deletions
diff --git a/guix-data-service/model/git-branch.scm b/guix-data-service/model/git-branch.scm
index a9b0202..78e149a 100644
--- a/guix-data-service/model/git-branch.scm
+++ b/guix-data-service/model/git-branch.scm
@@ -21,32 +21,52 @@
#:use-module (squee)
#:use-module (srfi srfi-19)
#:use-module (guix-data-service model utils)
- #:export (insert-git-branch-entry
+ #:export (git-branch-for-repository-and-name
+ insert-git-branch-entry
git-branches-for-commit
git-branches-with-repository-details-for-commit
most-recent-commits-for-branch
latest-processed-commit-for-branch
all-branches-with-most-recent-commit))
+(define (git-branch-for-repository-and-name conn
+ git-repository-id
+ name)
+ (match (exec-query
+ conn
+ "
+SELECT id
+FROM git_branches
+WHERE git_repository_id = $1
+ AND name = $2"
+ (list (number->string git-repository-id)
+ name))
+ (#f #f)
+ (((id)) (string->number id))))
+
(define (insert-git-branch-entry conn
- name commit
- git-repository-id datetime)
- (exec-query
- conn
- (string-append
- "INSERT INTO git_branches (name, commit, git_repository_id, datetime) "
- "VALUES ($1, $2, $3, to_timestamp($4)) "
- "ON CONFLICT DO NOTHING")
- (list name
- commit
- (number->string git-repository-id)
- (date->string datetime "~s"))))
+ git-repository-id
+ name)
+ (match (exec-query
+ conn
+ "
+INSERT INTO git_branches (git_repository_id, name)
+VALUES ($1, $2)
+RETURNING id"
+ (list (number->string git-repository-id)
+ name))
+ (((id))
+ (string->number id))))
(define (git-branches-for-commit conn commit)
(define query
"
-SELECT name, datetime FROM git_branches WHERE commit = $1
-ORDER BY datetime DESC")
+SELECT name, git_commits.datetime
+FROM git_commits
+INNER JOIN git_branches
+ ON git_commits.git_branch_id = git_branches.id
+WHERE commit = $1
+ORDER BY git_commits.datetime DESC")
(exec-query conn query (list commit)))
@@ -55,16 +75,49 @@ ORDER BY datetime DESC")
"
SELECT git_repositories.id, git_repositories.label,
git_repositories.url, git_repositories.cgit_url_base,
- git_branches.name, git_branches.datetime
-FROM git_branches
+ git_branches.name, git_commits.datetime
+FROM git_commits
+INNER JOIN git_branches
+ ON git_commits.git_branch_id = git_branches.id
INNER JOIN git_repositories
ON git_branches.git_repository_id = git_repositories.id
-WHERE git_branches.commit = $1")
+WHERE git_commits.commit = $1")
(group-list-by-first-n-fields
4
(exec-query conn query (list commit))))
+(define* (latest-processed-commit-for-branch conn repository-id branch-name)
+ (define query
+ (string-append
+ "
+SELECT git_commits.commit
+FROM git_branches
+INNER JOIN git_commits
+ ON git_branches.id = git_commits.git_branch_id
+INNER JOIN guix_revisions
+ ON git_commits.commit = guix_revisions.commit
+INNER JOIN load_new_guix_revision_jobs
+ ON load_new_guix_revision_jobs.commit = guix_revisions.commit
+INNER JOIN load_new_guix_revision_job_events
+ ON job_id = load_new_guix_revision_jobs.id
+WHERE guix_revisions.git_repository_id = $1
+ AND git_branches.git_repository_id = $1
+ AND git_branches.name = $2
+ AND load_new_guix_revision_job_events.event = 'success'
+ORDER BY datetime DESC
+LIMIT 1"))
+
+ (match (exec-query
+ conn
+ query
+ (list repository-id branch-name))
+ (((commit-hash))
+ commit-hash)
+ ('()
+ #f)))
+
+
(define* (most-recent-commits-for-branch conn git-repository-id
branch-name
#:key
@@ -74,7 +127,7 @@ WHERE git_branches.commit = $1")
(define query
(string-append
"
-SELECT git_branches.commit,
+SELECT git_commits.commit,
datetime,
(
load_new_guix_revision_job_events.event IS NOT NULL
@@ -84,12 +137,14 @@ SELECT git_branches.commit,
FROM load_new_guix_revision_job_events
INNER JOIN load_new_guix_revision_jobs ON
load_new_guix_revision_jobs.id = load_new_guix_revision_job_events.job_id
- WHERE load_new_guix_revision_jobs.commit = git_branches.commit AND
+ WHERE load_new_guix_revision_jobs.commit = git_commits.commit AND
git_branches.git_repository_id = load_new_guix_revision_jobs.git_repository_id
) AS job_events
FROM git_branches
+INNER JOIN git_commits
+ ON git_branches.id = git_commits.git_branch_id
LEFT OUTER JOIN guix_revisions
- ON git_branches.commit = guix_revisions.commit
+ ON git_commits.commit = guix_revisions.commit
LEFT JOIN load_new_guix_revision_jobs
ON load_new_guix_revision_jobs.commit = guix_revisions.commit
LEFT JOIN load_new_guix_revision_job_events
@@ -129,40 +184,12 @@ LIMIT " (number->string limit))
(list branch-name
(number->string git-repository-id)))))
-(define* (latest-processed-commit-for-branch conn repository-id branch-name)
- (define query
- (string-append
- "
-SELECT git_branches.commit
-FROM git_branches
-INNER JOIN guix_revisions
- ON git_branches.commit = guix_revisions.commit
-INNER JOIN load_new_guix_revision_jobs
- ON load_new_guix_revision_jobs.commit = guix_revisions.commit
-INNER JOIN load_new_guix_revision_job_events
- ON job_id = load_new_guix_revision_jobs.id
-WHERE guix_revisions.git_repository_id = $1
- AND git_branches.git_repository_id = $1
- AND git_branches.name = $2
- AND load_new_guix_revision_job_events.event = 'success'
-ORDER BY datetime DESC
-LIMIT 1"))
-
- (match (exec-query
- conn
- query
- (list repository-id branch-name))
- (((commit-hash))
- commit-hash)
- ('()
- #f)))
-
(define (all-branches-with-most-recent-commit conn git-repository-id)
(define query
(string-append
"
SELECT DISTINCT ON (name)
- name, git_branches.commit,
+ name, git_commits.commit,
datetime,
(
load_new_guix_revision_jobs.succeeded_at IS NOT NULL
@@ -172,14 +199,16 @@ SELECT DISTINCT ON (name)
FROM load_new_guix_revision_job_events
INNER JOIN load_new_guix_revision_jobs ON
load_new_guix_revision_jobs.id = load_new_guix_revision_job_events.job_id
- WHERE load_new_guix_revision_jobs.commit = git_branches.commit AND
+ WHERE load_new_guix_revision_jobs.commit = git_commits.commit AND
git_branches.git_repository_id = load_new_guix_revision_jobs.git_repository_id
) AS job_events
FROM git_branches
+INNER JOIN git_commits
+ ON git_branches.id = git_commits.git_branch_id
LEFT OUTER JOIN guix_revisions
- ON git_branches.commit = guix_revisions.commit
+ ON git_commits.commit = guix_revisions.commit
LEFT JOIN load_new_guix_revision_jobs
- ON git_branches.commit = load_new_guix_revision_jobs.commit
+ ON git_commits.commit = load_new_guix_revision_jobs.commit
AND git_branches.git_repository_id = load_new_guix_revision_jobs.git_repository_id
WHERE git_branches.git_repository_id = $1
ORDER BY name, datetime DESC"))
@@ -199,4 +228,3 @@ ORDER BY name, datetime DESC"))
conn
query
(list (number->string git-repository-id)))))
-