-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.lisp
151 lines (139 loc) · 5.58 KB
/
models.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(uiop:define-package #:quickdocs-api/models
(:use #:cl
#:sxql)
(:use-reexport #:dist-updater/models)
(:import-from #:alexandria
#:when-let
#:starts-with-subseq)
(:export #:release-systems
#:release-primary-system
#:release-description
#:release-authors
#:release-maintainers
#:release-licenses
#:release-depends-on
#:release-required-by
#:system-dependencies
#:find-latest-dist
#:dist-updated-projects))
(in-package #:quickdocs-api/models)
(defun release-systems (release)
(mito:select-dao 'system
(where (:= :release release))
(order-by :name)))
(defun release-primary-system (release)
(check-type release release)
(mito:find-dao 'system
:release release
:is-primary t))
(defun release-description (release)
(check-type release release)
(getf (first
(mito:retrieve-by-sql
(select (:description)
(from :system)
(where (:and (:= :release_id (mito:object-id release))
(:= :is_primary "true")
(:not-null :description)))
(limit 1))))
:description))
(defun release-authors (release)
(check-type release release)
(let ((systems (release-systems release)))
(delete-duplicates
(loop for system in systems
append (coerce (system-authors system) 'list))
:test #'string=
:from-end t)))
(defun release-maintainers (release)
(check-type release release)
(let ((systems (release-systems release)))
(delete-duplicates
(loop for system in systems
append (coerce (system-maintainers system) 'list))
:test #'string=
:from-end t)))
(defun release-licenses (release)
(check-type release release)
(let ((systems (release-systems release)))
(delete-duplicates
(loop for system in systems
if (system-license system)
collect (system-license system))
:test #'string=
:from-end t)))
(defun release-readme-files (release)
(mito:select-dao 'readme-file
(where (:= :release release))
(order-by :filename)))
(defun release-depends-on (release dist)
(let* ((systems (release-systems release))
(depends-system-names
(mapcar (lambda (row)
(getf row :name))
(mito:retrieve-by-sql
(select (:system_dependency.name)
(from :system_dependency)
(join :system :on (:= :system.id :system_dependency.system_id))
(join :release :on (:= :release.id :system.release_id))
(where `(:and (:= :release.id ,(mito:object-id release))
,@(and systems
`((:not-in :system_dependency.name ,(mapcar #'system-name systems))))))
(group-by :system_dependency.name))))))
(when depends-system-names
(mapcar (lambda (row)
(getf row :name))
(mito:retrieve-by-sql
(select (:release.name)
(from :release)
(join :dist_release :on (:= :dist_release.release_id :release.id))
(join :system :on (:= :system.release_id :release.id))
(where (:and (:= :dist_release.dist_id (mito:object-id dist))
(:in :system.name depends-system-names)))
(group-by :release.name)
(order-by :release.name)))))))
(defun release-required-by (release dist)
(when-let ((systems (release-systems release)))
(mapcar (lambda (row)
(getf row :name))
(mito:retrieve-by-sql
(select (:release.name)
(from :system_dependency)
(left-join :system :on (:= :system.id :system_dependency.system_id))
(left-join :release :on (:= :release.id :system.release_id))
(left-join :dist_release :on (:= :dist_release.release_id :release.id))
(where (:and (:= :dist_release.dist_id (mito:object-id dist))
(:in :system_dependency.name (mapcar #'system-name systems))
(:!= :release.name (release-name release))))
(group-by :release.name)
(order-by :release.name))))))
(defun system-dependencies (system)
(mito:select-dao 'system-dependency
(where (:= :system system))))
(defun find-latest-dist ()
(first (mito:select-dao 'dist
(where (:= :name "quicklisp"))
(order-by (:desc :version))
(limit 1))))
(defun dist-updated-projects (dist)
(remove-duplicates
(mito:retrieve-by-sql
(select (:r1.name
:system.description
(:as (:case
(:when (:is-null :r2.dist_version) (:raw "true"))
(:else (:raw "false")))
:is_new))
(from (:as :release :r1))
(left-join (:as :release :r2)
:on (:and (:= :r1.name :r2.name)
(:= :r1.dist_name :r2.dist_name)
(:< :r2.dist_version :r1.dist_version)))
(left-join :system :on (:and (:= :release_id :r1.id)
(:= :is_primary "true")))
(where (:and (:= :r1.dist_name "quicklisp")
(:= :r1.dist_version (dist-version dist))))
(order-by :r1.name)))
:key (lambda (row) (getf row :name))
:test 'equal
:from-end t))