Merge ~cjwatson/launchpad:stormify-distribution-caches into launchpad:master
- Git
- lp:~cjwatson/launchpad
- stormify-distribution-caches
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | c21902ec6834509417de56da16cbc8bad31c572e |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:stormify-distribution-caches |
Merge into: | launchpad:master |
Diff against target: |
705 lines (+217/-115) 11 files modified
lib/lp/registry/model/distribution.py (+3/-3) lib/lp/registry/model/distroseries.py (+1/-1) lib/lp/registry/vocabularies.py (+5/-5) lib/lp/scripts/garbo.py (+11/-7) lib/lp/soyuz/doc/package-cache.rst (+94/-32) lib/lp/soyuz/model/archive.py (+13/-6) lib/lp/soyuz/model/distributionsourcepackagecache.py (+40/-25) lib/lp/soyuz/model/distributionsourcepackagerelease.py (+1/-1) lib/lp/soyuz/model/distroarchseriesbinarypackage.py (+12/-11) lib/lp/soyuz/model/distroseriesbinarypackage.py (+1/-1) lib/lp/soyuz/model/distroseriespackagecache.py (+36/-23) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guruprasad | Approve | ||
Review via email: mp+435995@code.launchpad.net |
Commit message
Convert distribution/
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py |
2 | index af6ce95..80433cc 100644 |
3 | --- a/lib/lp/registry/model/distribution.py |
4 | +++ b/lib/lp/registry/model/distribution.py |
5 | @@ -1581,7 +1581,7 @@ class Distribution( |
6 | conditions = [ |
7 | DistributionSourcePackageCache.distribution == self, |
8 | Or( |
9 | - DistributionSourcePackageCache.archiveID.is_in( |
10 | + DistributionSourcePackageCache.archive_id.is_in( |
11 | self.all_distro_archive_ids |
12 | ), |
13 | DistributionSourcePackageCache.archive == None, |
14 | @@ -1613,7 +1613,7 @@ class Distribution( |
15 | Join( |
16 | SourcePackagePublishingHistory, |
17 | SourcePackagePublishingHistory.sourcepackagenameID |
18 | - == DistributionSourcePackageCache.sourcepackagenameID, |
19 | + == DistributionSourcePackageCache.sourcepackagename_id, |
20 | ) |
21 | ) |
22 | conditions.extend( |
23 | @@ -1668,7 +1668,7 @@ class Distribution( |
24 | |
25 | find_spec = ( |
26 | DistributionSourcePackageCache.distribution == self, |
27 | - DistributionSourcePackageCache.archiveID.is_in( |
28 | + DistributionSourcePackageCache.archive_id.is_in( |
29 | self.all_distro_archive_ids |
30 | ), |
31 | ) |
32 | diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py |
33 | index 68f102f..0c7cbd8 100644 |
34 | --- a/lib/lp/registry/model/distroseries.py |
35 | +++ b/lib/lp/registry/model/distroseries.py |
36 | @@ -1290,7 +1290,7 @@ class DistroSeries( |
37 | .find( |
38 | find_spec, |
39 | DistroSeriesPackageCache.distroseries == self, |
40 | - DistroSeriesPackageCache.archiveID.is_in( |
41 | + DistroSeriesPackageCache.archive_id.is_in( |
42 | self.distribution.all_distro_archive_ids |
43 | ), |
44 | Or( |
45 | diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py |
46 | index df45ef0..59a48a8 100644 |
47 | --- a/lib/lp/registry/vocabularies.py |
48 | +++ b/lib/lp/registry/vocabularies.py |
49 | @@ -2098,7 +2098,7 @@ class SourcePackageNameVocabulary(NamedStormHugeVocabulary): |
50 | _clauses = [ |
51 | SourcePackageName.id.is_in( |
52 | Select( |
53 | - DistributionSourcePackageCache.sourcepackagenameID, |
54 | + DistributionSourcePackageCache.sourcepackagename_id, |
55 | # No current users of this vocabulary can easily provide a |
56 | # distribution context, since the distribution and source |
57 | # package name are typically selected together, so the best |
58 | @@ -2111,7 +2111,7 @@ class SourcePackageNameVocabulary(NamedStormHugeVocabulary): |
59 | tables=LeftJoin( |
60 | DistributionSourcePackageCache, |
61 | Archive, |
62 | - DistributionSourcePackageCache.archiveID == Archive.id, |
63 | + DistributionSourcePackageCache.archive_id == Archive.id, |
64 | ), |
65 | ) |
66 | ), |
67 | @@ -2214,7 +2214,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase): |
68 | def _cache_location_clauses(self): |
69 | return [ |
70 | Or( |
71 | - DistributionSourcePackageCache.archiveID.is_in( |
72 | + DistributionSourcePackageCache.archive_id.is_in( |
73 | self.distribution.all_distro_archive_ids |
74 | ), |
75 | DistributionSourcePackageCache.archive == None, |
76 | @@ -2260,7 +2260,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase): |
77 | empty = ( |
78 | IStore(DistributionSourcePackageCache) |
79 | .find( |
80 | - DistributionSourcePackageCache.sourcepackagenameID, |
81 | + DistributionSourcePackageCache.sourcepackagename_id, |
82 | *self._cache_location_clauses, |
83 | ) |
84 | .is_empty() |
85 | @@ -2302,7 +2302,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase): |
86 | Select( |
87 | ( |
88 | DSPC.name, |
89 | - DSPC.sourcepackagenameID, |
90 | + DSPC.sourcepackagename_id, |
91 | DSPC.binpkgnames, |
92 | ), |
93 | where=And( |
94 | diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py |
95 | index 3ec4d53..770c5d2 100644 |
96 | --- a/lib/lp/scripts/garbo.py |
97 | +++ b/lib/lp/scripts/garbo.py |
98 | @@ -544,16 +544,20 @@ class PopulateDistributionSourcePackageCache(TunableLoop): |
99 | DistributionSourcePackageCache, |
100 | In( |
101 | Row( |
102 | - DistributionSourcePackageCache.archiveID, |
103 | - DistributionSourcePackageCache.distributionID, |
104 | - DistributionSourcePackageCache.sourcepackagenameID, |
105 | + DistributionSourcePackageCache.archive_id, |
106 | + DistributionSourcePackageCache.distribution_id, |
107 | + DistributionSourcePackageCache.sourcepackagename_id, |
108 | ), |
109 | [Row(cache_key) for cache_key in cache_filter_data], |
110 | ), |
111 | ) |
112 | for dspc in rows: |
113 | existing_records.add( |
114 | - (dspc.archiveID, dspc.distributionID, dspc.sourcepackagenameID) |
115 | + ( |
116 | + dspc.archive_id, |
117 | + dspc.distribution_id, |
118 | + dspc.sourcepackagename_id, |
119 | + ) |
120 | ) |
121 | |
122 | # Bulk-create missing cache rows. |
123 | @@ -566,9 +570,9 @@ class PopulateDistributionSourcePackageCache(TunableLoop): |
124 | if inserts: |
125 | create( |
126 | ( |
127 | - DistributionSourcePackageCache.archiveID, |
128 | - DistributionSourcePackageCache.distributionID, |
129 | - DistributionSourcePackageCache.sourcepackagenameID, |
130 | + DistributionSourcePackageCache.archive_id, |
131 | + DistributionSourcePackageCache.distribution_id, |
132 | + DistributionSourcePackageCache.sourcepackagename_id, |
133 | DistributionSourcePackageCache.name, |
134 | ), |
135 | inserts, |
136 | diff --git a/lib/lp/soyuz/doc/package-cache.rst b/lib/lp/soyuz/doc/package-cache.rst |
137 | index 27b7c44..d74ac9a 100644 |
138 | --- a/lib/lp/soyuz/doc/package-cache.rst |
139 | +++ b/lib/lp/soyuz/doc/package-cache.rst |
140 | @@ -20,6 +20,7 @@ DistributionSourcePackageCache table, including: |
141 | generated by this source. |
142 | |
143 | >>> from lp.registry.interfaces.distribution import IDistributionSet |
144 | + >>> from lp.services.database.interfaces import IStore |
145 | >>> from lp.soyuz.model.distributionsourcepackagecache import ( |
146 | ... DistributionSourcePackageCache, |
147 | ... ) |
148 | @@ -112,8 +113,15 @@ cache when it's updated. |
149 | >>> ubuntu.searchSourcePackages("foobar").count() |
150 | 1 |
151 | |
152 | - >>> foobar_cache = DistributionSourcePackageCache.selectOneBy( |
153 | - ... archive=ubuntu.main_archive, distribution=ubuntu, name="foobar" |
154 | + >>> foobar_cache = ( |
155 | + ... IStore(DistributionSourcePackageCache) |
156 | + ... .find( |
157 | + ... DistributionSourcePackageCache, |
158 | + ... archive=ubuntu.main_archive, |
159 | + ... distribution=ubuntu, |
160 | + ... name="foobar", |
161 | + ... ) |
162 | + ... .one() |
163 | ... ) |
164 | |
165 | >>> foobar_cache is not None |
166 | @@ -136,8 +144,15 @@ Let's use a fake logger object: |
167 | >>> ubuntu.searchSourcePackages("foobar").count() |
168 | 0 |
169 | |
170 | - >>> foobar_cache = DistributionSourcePackageCache.selectOneBy( |
171 | - ... archive=ubuntu.main_archive, distribution=ubuntu, name="foobar" |
172 | + >>> foobar_cache = ( |
173 | + ... IStore(DistributionSourcePackageCache) |
174 | + ... .find( |
175 | + ... DistributionSourcePackageCache, |
176 | + ... archive=ubuntu.main_archive, |
177 | + ... distribution=ubuntu, |
178 | + ... name="foobar", |
179 | + ... ) |
180 | + ... .one() |
181 | ... ) |
182 | |
183 | >>> foobar_cache is None |
184 | @@ -155,8 +170,15 @@ cache when it's updated the next time. |
185 | >>> ubuntu.searchSourcePackages("cdrkit").count() |
186 | 0 |
187 | |
188 | - >>> cdrkit_cache = DistributionSourcePackageCache.selectOneBy( |
189 | - ... archive=ubuntu.main_archive, distribution=ubuntu, name="cdrkit" |
190 | + >>> cdrkit_cache = ( |
191 | + ... IStore(DistributionSourcePackageCache) |
192 | + ... .find( |
193 | + ... DistributionSourcePackageCache, |
194 | + ... archive=ubuntu.main_archive, |
195 | + ... distribution=ubuntu, |
196 | + ... name="cdrkit", |
197 | + ... ) |
198 | + ... .one() |
199 | ... ) |
200 | |
201 | >>> cdrkit_cache is None |
202 | @@ -185,8 +207,15 @@ reached via searches: |
203 | >>> ubuntu.searchSourcePackages("cdrkit").count() |
204 | 1 |
205 | |
206 | - >>> cdrkit_cache = DistributionSourcePackageCache.selectOneBy( |
207 | - ... archive=ubuntu.main_archive, distribution=ubuntu, name="cdrkit" |
208 | + >>> cdrkit_cache = ( |
209 | + ... IStore(DistributionSourcePackageCache) |
210 | + ... .find( |
211 | + ... DistributionSourcePackageCache, |
212 | + ... archive=ubuntu.main_archive, |
213 | + ... distribution=ubuntu, |
214 | + ... name="cdrkit", |
215 | + ... ) |
216 | + ... .one() |
217 | ... ) |
218 | |
219 | >>> cdrkit_cache is not None |
220 | @@ -208,8 +237,15 @@ cache when it's updated. |
221 | >>> warty.searchPackages("foobar").count() |
222 | 1 |
223 | |
224 | - >>> foobar_bin_cache = DistroSeriesPackageCache.selectOneBy( |
225 | - ... archive=ubuntu.main_archive, distroseries=warty, name="foobar" |
226 | + >>> foobar_bin_cache = ( |
227 | + ... IStore(DistroSeriesPackageCache) |
228 | + ... .find( |
229 | + ... DistroSeriesPackageCache, |
230 | + ... archive=ubuntu.main_archive, |
231 | + ... distroseries=warty, |
232 | + ... name="foobar", |
233 | + ... ) |
234 | + ... .one() |
235 | ... ) |
236 | |
237 | >>> foobar_bin_cache is not None |
238 | @@ -228,8 +264,15 @@ offers a method for removing obsolete records in cache: |
239 | >>> warty.searchPackages("foobar").count() |
240 | 0 |
241 | |
242 | - >>> foobar_bin_cache = DistroSeriesPackageCache.selectOneBy( |
243 | - ... archive=ubuntu.main_archive, distroseries=warty, name="foobar" |
244 | + >>> foobar_bin_cache = ( |
245 | + ... IStore(DistroSeriesPackageCache) |
246 | + ... .find( |
247 | + ... DistroSeriesPackageCache, |
248 | + ... archive=ubuntu.main_archive, |
249 | + ... distroseries=warty, |
250 | + ... name="foobar", |
251 | + ... ) |
252 | + ... .one() |
253 | ... ) |
254 | |
255 | >>> foobar_bin_cache is None |
256 | @@ -246,8 +289,15 @@ cache will be added to it. |
257 | >>> warty.searchPackages("cdrkit").count() |
258 | 0 |
259 | |
260 | - >>> cdrkit_bin_cache = DistroSeriesPackageCache.selectOneBy( |
261 | - ... archive=ubuntu.main_archive, distroseries=warty, name="cdrkit" |
262 | + >>> cdrkit_bin_cache = ( |
263 | + ... IStore(DistroSeriesPackageCache) |
264 | + ... .find( |
265 | + ... DistroSeriesPackageCache, |
266 | + ... archive=ubuntu.main_archive, |
267 | + ... distroseries=warty, |
268 | + ... name="cdrkit", |
269 | + ... ) |
270 | + ... .one() |
271 | ... ) |
272 | |
273 | >>> cdrkit_bin_cache is None |
274 | @@ -281,8 +331,15 @@ reached via searches: |
275 | >>> warty.searchPackages("cdrkit").count() |
276 | 1 |
277 | |
278 | - >>> cdrkit_bin_cache = DistroSeriesPackageCache.selectOneBy( |
279 | - ... archive=ubuntu.main_archive, distroseries=warty, name="cdrkit" |
280 | + >>> cdrkit_bin_cache = ( |
281 | + ... IStore(DistroSeriesPackageCache) |
282 | + ... .find( |
283 | + ... DistroSeriesPackageCache, |
284 | + ... archive=ubuntu.main_archive, |
285 | + ... distroseries=warty, |
286 | + ... name="cdrkit", |
287 | + ... ) |
288 | + ... .one() |
289 | ... ) |
290 | |
291 | >>> cdrkit_bin_cache is not None |
292 | @@ -400,19 +457,17 @@ the following tasks: |
293 | |
294 | We remove all caches related to Celso's PPA. |
295 | |
296 | - >>> celso_source_caches = DistributionSourcePackageCache.selectBy( |
297 | - ... archive=cprov.archive |
298 | + >>> celso_source_caches = IStore(DistributionSourcePackageCache).find( |
299 | + ... DistributionSourcePackageCache, archive=cprov.archive |
300 | ... ) |
301 | |
302 | - >>> celso_binary_caches = DistroSeriesPackageCache.selectBy( |
303 | - ... archive=cprov.archive |
304 | + >>> celso_binary_caches = IStore(DistroSeriesPackageCache).find( |
305 | + ... DistroSeriesPackageCache, archive=cprov.archive |
306 | ... ) |
307 | |
308 | - >>> from zope.security.proxy import removeSecurityProxy |
309 | >>> def purge_caches(caches): |
310 | ... for cache in caches: |
311 | - ... naked_cache = removeSecurityProxy(cache) |
312 | - ... naked_cache.destroySelf() |
313 | + ... IStore(cache).remove(cache) |
314 | ... |
315 | |
316 | >>> purge_caches(celso_source_caches) |
317 | @@ -471,7 +526,7 @@ unique and lowercase words free of any punctuation. |
318 | Let's remove the unclean cache and update Celso's PPA cache, so |
319 | everything will be back to normal. |
320 | |
321 | - >>> removeSecurityProxy(unclean_cache).destroySelf() |
322 | + >>> IStore(unclean_cache).remove(unclean_cache) |
323 | >>> cprov.archive.updateArchiveCache() |
324 | |
325 | |
326 | @@ -501,12 +556,17 @@ with a null archive column. |
327 | |
328 | Updating the cache adds missing entries to the cache. |
329 | |
330 | - >>> branch_cache = DistributionSourcePackageCache.selectOneBy( |
331 | - ... archive=None, |
332 | - ... distribution=ubuntu, |
333 | - ... name=branch.sourcepackagename.name, |
334 | + >>> branch_cache = ( |
335 | + ... IStore(DistributionSourcePackageCache) |
336 | + ... .find( |
337 | + ... DistributionSourcePackageCache, |
338 | + ... archive=None, |
339 | + ... distribution=ubuntu, |
340 | + ... name=branch.sourcepackagename.name, |
341 | + ... ) |
342 | + ... .one() |
343 | ... ) |
344 | - >>> removeSecurityProxy(branch_cache).destroySelf() |
345 | + >>> IStore(branch_cache).remove(branch_cache) |
346 | >>> ubuntu.searchSourcePackages(branch.sourcepackagename.name).count() |
347 | 0 |
348 | >>> updates = DistributionSourcePackageCache.updateAll( |
349 | @@ -780,10 +840,12 @@ First, we rebuild and examinate the caches for Celso's PPA. |
350 | ... archive.updateArchiveCache() |
351 | ... |
352 | >>> def print_caches(archive): |
353 | - ... source_caches = DistributionSourcePackageCache.selectBy( |
354 | - ... archive=archive |
355 | + ... source_caches = IStore(DistributionSourcePackageCache).find( |
356 | + ... DistributionSourcePackageCache, archive=archive |
357 | + ... ) |
358 | + ... binary_caches = IStore(DistroSeriesPackageCache).find( |
359 | + ... DistroSeriesPackageCache, archive=archive |
360 | ... ) |
361 | - ... binary_caches = DistroSeriesPackageCache.selectBy(archive=archive) |
362 | ... print( |
363 | ... "%d sources cached [%d]" |
364 | ... % (archive.sources_cached, source_caches.count()) |
365 | diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py |
366 | index ec04a41..c04e77f 100644 |
367 | --- a/lib/lp/soyuz/model/archive.py |
368 | +++ b/lib/lp/soyuz/model/archive.py |
369 | @@ -1205,6 +1205,9 @@ class Archive(SQLBase): |
370 | |
371 | def updateArchiveCache(self): |
372 | """See `IArchive`.""" |
373 | + # Circular imports. |
374 | + from lp.registry.model.distribution import Distribution |
375 | + from lp.registry.model.distroseries import DistroSeries |
376 | from lp.soyuz.model.distributionsourcepackagecache import ( |
377 | DistributionSourcePackageCache, |
378 | ) |
379 | @@ -1235,20 +1238,24 @@ class Archive(SQLBase): |
380 | |
381 | # Cache source package name and its binaries information, binary |
382 | # names and summaries. |
383 | - sources_cached = DistributionSourcePackageCache.select( |
384 | - "archive = %s" % sqlvalues(self), prejoins=["distribution"] |
385 | + sources_cached = IStore(DistributionSourcePackageCache).find( |
386 | + (DistributionSourcePackageCache, Distribution), |
387 | + DistributionSourcePackageCache.archive == self, |
388 | + DistributionSourcePackageCache.distribution_id == Distribution.id, |
389 | ) |
390 | - for cache in sources_cached: |
391 | + for cache, _ in sources_cached: |
392 | add_cache_content(cache.distribution.name) |
393 | add_cache_content(cache.name) |
394 | add_cache_content(cache.binpkgnames) |
395 | add_cache_content(cache.binpkgsummaries) |
396 | |
397 | # Cache distroseries names with binaries. |
398 | - binaries_cached = DistroSeriesPackageCache.select( |
399 | - "archive = %s" % sqlvalues(self), prejoins=["distroseries"] |
400 | + binaries_cached = IStore(DistroSeriesPackageCache).find( |
401 | + (DistroSeriesPackageCache, DistroSeries), |
402 | + DistroSeriesPackageCache.archive == self, |
403 | + DistroSeriesPackageCache.distroseries_id == DistroSeries.id, |
404 | ) |
405 | - for cache in binaries_cached: |
406 | + for cache, _ in binaries_cached: |
407 | add_cache_content(cache.distroseries.name) |
408 | |
409 | # Collapse all relevant terms in 'package_description_cache' and |
410 | diff --git a/lib/lp/soyuz/model/distributionsourcepackagecache.py b/lib/lp/soyuz/model/distributionsourcepackagecache.py |
411 | index e4a3837..31ee732 100644 |
412 | --- a/lib/lp/soyuz/model/distributionsourcepackagecache.py |
413 | +++ b/lib/lp/soyuz/model/distributionsourcepackagecache.py |
414 | @@ -8,6 +8,7 @@ __all__ = [ |
415 | from collections import defaultdict |
416 | from operator import attrgetter, itemgetter |
417 | |
418 | +from storm.locals import Int, Reference, Unicode |
419 | from zope.interface import implementer |
420 | |
421 | from lp.code.model.seriessourcepackagebranch import SeriesSourcePackageBranch |
422 | @@ -16,8 +17,7 @@ from lp.registry.model.sourcepackagename import SourcePackageName |
423 | from lp.services.database import bulk |
424 | from lp.services.database.decoratedresultset import DecoratedResultSet |
425 | from lp.services.database.interfaces import IStore |
426 | -from lp.services.database.sqlbase import SQLBase |
427 | -from lp.services.database.sqlobject import ForeignKey, StringCol |
428 | +from lp.services.database.stormbase import StormBase |
429 | from lp.soyuz.interfaces.distributionsourcepackagecache import ( |
430 | IDistributionSourcePackageCache, |
431 | ) |
432 | @@ -32,24 +32,39 @@ _DEFAULT = object() |
433 | |
434 | |
435 | @implementer(IDistributionSourcePackageCache) |
436 | -class DistributionSourcePackageCache(SQLBase): |
437 | - _table = "DistributionSourcePackageCache" |
438 | - |
439 | - archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=False) |
440 | - distribution = ForeignKey( |
441 | - dbName="distribution", foreignKey="Distribution", notNull=True |
442 | - ) |
443 | - sourcepackagename = ForeignKey( |
444 | - dbName="sourcepackagename", |
445 | - foreignKey="SourcePackageName", |
446 | - notNull=True, |
447 | - ) |
448 | - |
449 | - name = StringCol(notNull=False, default=None) |
450 | - binpkgnames = StringCol(notNull=False, default=None) |
451 | - binpkgsummaries = StringCol(notNull=False, default=None) |
452 | - binpkgdescriptions = StringCol(notNull=False, default=None) |
453 | - changelog = StringCol(notNull=False, default=None) |
454 | +class DistributionSourcePackageCache(StormBase): |
455 | + __storm_table__ = "DistributionSourcePackageCache" |
456 | + |
457 | + id = Int(primary=True) |
458 | + archive_id = Int(name="archive", allow_none=True) |
459 | + archive = Reference(archive_id, "Archive.id") |
460 | + distribution_id = Int(name="distribution", allow_none=False) |
461 | + distribution = Reference(distribution_id, "Distribution.id") |
462 | + sourcepackagename_id = Int(name="sourcepackagename", allow_none=False) |
463 | + sourcepackagename = Reference(sourcepackagename_id, "SourcePackageName.id") |
464 | + |
465 | + name = Unicode(allow_none=True, default=None) |
466 | + binpkgnames = Unicode(allow_none=True, default=None) |
467 | + binpkgsummaries = Unicode(allow_none=True, default=None) |
468 | + binpkgdescriptions = Unicode(allow_none=True, default=None) |
469 | + changelog = Unicode(allow_none=True, default=None) |
470 | + |
471 | + def __init__( |
472 | + self, |
473 | + archive, |
474 | + distribution, |
475 | + sourcepackagename, |
476 | + name=None, |
477 | + binpkgnames=None, |
478 | + binpkgsummaries=None, |
479 | + ): |
480 | + super().__init__() |
481 | + self.archive = archive |
482 | + self.distribution = distribution |
483 | + self.sourcepackagename = sourcepackagename |
484 | + self.name = name |
485 | + self.binpkgnames = binpkgnames |
486 | + self.binpkgsummaries = binpkgsummaries |
487 | |
488 | @property |
489 | def distributionsourcepackage(self): |
490 | @@ -89,7 +104,7 @@ class DistributionSourcePackageCache(SQLBase): |
491 | If 'archive' is not given it will return all caches stored for the |
492 | distribution main archives (PRIMARY and PARTNER). |
493 | """ |
494 | - archive_column = DistributionSourcePackageCache.archiveID |
495 | + archive_column = DistributionSourcePackageCache.archive_id |
496 | if archive is _DEFAULT: |
497 | archive_clause = archive_column.is_in( |
498 | distro.all_distro_archive_ids |
499 | @@ -106,7 +121,7 @@ class DistributionSourcePackageCache(SQLBase): |
500 | DistributionSourcePackageCache.distribution == distro, |
501 | archive_clause, |
502 | SourcePackageName.id |
503 | - == DistributionSourcePackageCache.sourcepackagenameID, |
504 | + == DistributionSourcePackageCache.sourcepackagename_id, |
505 | ) |
506 | .order_by(DistributionSourcePackageCache.name) |
507 | ) |
508 | @@ -137,7 +152,7 @@ class DistributionSourcePackageCache(SQLBase): |
509 | "Removing source cache for '%s' (%s)" |
510 | % (cache.name, cache.id) |
511 | ) |
512 | - cache.destroySelf() |
513 | + IStore(cache).remove(cache) |
514 | |
515 | @classmethod |
516 | def update( |
517 | @@ -180,7 +195,7 @@ class DistributionSourcePackageCache(SQLBase): |
518 | cls, |
519 | cls.distribution == distro, |
520 | cls.archive == archive, |
521 | - cls.sourcepackagenameID.is_in( |
522 | + cls.sourcepackagename_id.is_in( |
523 | [spn.id for spn in sourcepackagenames] |
524 | ), |
525 | ) |
526 | @@ -285,7 +300,7 @@ class DistributionSourcePackageCache(SQLBase): |
527 | cls, |
528 | cls.distribution == distro, |
529 | cls.archive == None, |
530 | - cls.sourcepackagenameID.is_in( |
531 | + cls.sourcepackagename_id.is_in( |
532 | [spn.id for spn in sourcepackagenames] |
533 | ), |
534 | ) |
535 | diff --git a/lib/lp/soyuz/model/distributionsourcepackagerelease.py b/lib/lp/soyuz/model/distributionsourcepackagerelease.py |
536 | index 1f7e663..9002ce6 100644 |
537 | --- a/lib/lp/soyuz/model/distributionsourcepackagerelease.py |
538 | +++ b/lib/lp/soyuz/model/distributionsourcepackagerelease.py |
539 | @@ -189,7 +189,7 @@ class DistributionSourcePackageRelease: |
540 | DistroSeriesPackageCache, |
541 | And( |
542 | DistroSeriesPackageCache.distroseries == DistroSeries.id, |
543 | - DistroSeriesPackageCache.archiveID.is_in(archive_ids), |
544 | + DistroSeriesPackageCache.archive_id.is_in(archive_ids), |
545 | DistroSeriesPackageCache.binarypackagename |
546 | == BinaryPackageName.id, |
547 | ), |
548 | diff --git a/lib/lp/soyuz/model/distroarchseriesbinarypackage.py b/lib/lp/soyuz/model/distroarchseriesbinarypackage.py |
549 | index 035c96a..d85b423 100644 |
550 | --- a/lib/lp/soyuz/model/distroarchseriesbinarypackage.py |
551 | +++ b/lib/lp/soyuz/model/distroarchseriesbinarypackage.py |
552 | @@ -13,7 +13,6 @@ from zope.interface import implementer |
553 | |
554 | from lp.app.errors import NotFoundError |
555 | from lp.services.database.interfaces import IStore |
556 | -from lp.services.database.sqlbase import sqlvalues |
557 | from lp.services.propertycache import cachedproperty |
558 | from lp.soyuz.enums import PackagePublishingStatus |
559 | from lp.soyuz.interfaces.distroarchseriesbinarypackage import ( |
560 | @@ -78,18 +77,20 @@ class DistroArchSeriesBinaryPackage: |
561 | DistroSeriesPackageCache, |
562 | ) |
563 | |
564 | - query = """ |
565 | - distroseries = %s AND |
566 | - archive IN %s AND |
567 | - binarypackagename = %s |
568 | - """ % sqlvalues( |
569 | - self.distroseries, |
570 | - self.distribution.all_distro_archive_ids, |
571 | - self.binarypackagename, |
572 | + return ( |
573 | + IStore(DistroSeriesPackageCache) |
574 | + .find( |
575 | + DistroSeriesPackageCache, |
576 | + DistroSeriesPackageCache.distroseries == self.distroseries, |
577 | + DistroSeriesPackageCache.archive_id.is_in( |
578 | + self.distribution.all_distro_archive_ids |
579 | + ), |
580 | + DistroSeriesPackageCache.binarypackagename |
581 | + == self.binarypackagename, |
582 | + ) |
583 | + .one() |
584 | ) |
585 | |
586 | - return DistroSeriesPackageCache.selectOne(query) |
587 | - |
588 | @property |
589 | def summary(self): |
590 | """See IDistroArchSeriesBinaryPackage.""" |
591 | diff --git a/lib/lp/soyuz/model/distroseriesbinarypackage.py b/lib/lp/soyuz/model/distroseriesbinarypackage.py |
592 | index 8946c36..3e3f4c5 100644 |
593 | --- a/lib/lp/soyuz/model/distroseriesbinarypackage.py |
594 | +++ b/lib/lp/soyuz/model/distroseriesbinarypackage.py |
595 | @@ -68,7 +68,7 @@ class DistroSeriesBinaryPackage: |
596 | result = store.find( |
597 | DistroSeriesPackageCache, |
598 | DistroSeriesPackageCache.distroseries == self.distroseries, |
599 | - DistroSeriesPackageCache.archiveID.is_in(archive_ids), |
600 | + DistroSeriesPackageCache.archive_id.is_in(archive_ids), |
601 | ( |
602 | DistroSeriesPackageCache.binarypackagename |
603 | == self.binarypackagename |
604 | diff --git a/lib/lp/soyuz/model/distroseriespackagecache.py b/lib/lp/soyuz/model/distroseriespackagecache.py |
605 | index 2bb7d52..bc7a9bc 100644 |
606 | --- a/lib/lp/soyuz/model/distroseriespackagecache.py |
607 | +++ b/lib/lp/soyuz/model/distroseriespackagecache.py |
608 | @@ -9,12 +9,12 @@ from collections import defaultdict |
609 | from operator import attrgetter |
610 | |
611 | from storm.expr import Desc, Max, Select |
612 | +from storm.locals import Int, Reference, Unicode |
613 | from zope.interface import implementer |
614 | |
615 | from lp.services.database import bulk |
616 | from lp.services.database.interfaces import IStore |
617 | -from lp.services.database.sqlbase import SQLBase |
618 | -from lp.services.database.sqlobject import ForeignKey, StringCol |
619 | +from lp.services.database.stormbase import StormBase |
620 | from lp.soyuz.interfaces.distroseriespackagecache import ( |
621 | IDistroSeriesPackageCache, |
622 | ) |
623 | @@ -26,24 +26,37 @@ from lp.soyuz.model.publishing import BinaryPackagePublishingHistory |
624 | |
625 | |
626 | @implementer(IDistroSeriesPackageCache) |
627 | -class DistroSeriesPackageCache(SQLBase): |
628 | - _table = "DistroSeriesPackageCache" |
629 | - |
630 | - archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=True) |
631 | - distroseries = ForeignKey( |
632 | - dbName="distroseries", foreignKey="DistroSeries", notNull=True |
633 | - ) |
634 | - binarypackagename = ForeignKey( |
635 | - dbName="binarypackagename", |
636 | - foreignKey="BinaryPackageName", |
637 | - notNull=True, |
638 | - ) |
639 | - |
640 | - name = StringCol(notNull=False, default=None) |
641 | - summary = StringCol(notNull=False, default=None) |
642 | - description = StringCol(notNull=False, default=None) |
643 | - summaries = StringCol(notNull=False, default=None) |
644 | - descriptions = StringCol(notNull=False, default=None) |
645 | +class DistroSeriesPackageCache(StormBase): |
646 | + __storm_table__ = "DistroSeriesPackageCache" |
647 | + |
648 | + id = Int(primary=True) |
649 | + archive_id = Int(name="archive", allow_none=False) |
650 | + archive = Reference(archive_id, "Archive.id") |
651 | + distroseries_id = Int(name="distroseries", allow_none=False) |
652 | + distroseries = Reference(distroseries_id, "DistroSeries.id") |
653 | + binarypackagename_id = Int(name="binarypackagename", allow_none=False) |
654 | + binarypackagename = Reference(binarypackagename_id, "BinaryPackageName.id") |
655 | + |
656 | + name = Unicode(allow_none=True, default=None) |
657 | + summary = Unicode(allow_none=True, default=None) |
658 | + description = Unicode(allow_none=True, default=None) |
659 | + summaries = Unicode(allow_none=True, default=None) |
660 | + descriptions = Unicode(allow_none=True, default=None) |
661 | + |
662 | + def __init__( |
663 | + self, |
664 | + archive, |
665 | + distroseries, |
666 | + binarypackagename, |
667 | + summary=None, |
668 | + description=None, |
669 | + ): |
670 | + super().__init__() |
671 | + self.archive = archive |
672 | + self.distroseries = distroseries |
673 | + self.binarypackagename = binarypackagename |
674 | + self.summary = summary |
675 | + self.description = description |
676 | |
677 | @classmethod |
678 | def findCurrentBinaryPackageNames(cls, archive, distroseries): |
679 | @@ -84,7 +97,7 @@ class DistroSeriesPackageCache(SQLBase): |
680 | .find( |
681 | cls, |
682 | cls.distroseries == distroseries, |
683 | - cls.archiveID.is_in(archives), |
684 | + cls.archive_id.is_in(archives), |
685 | ) |
686 | .order_by(cls.name) |
687 | ) |
688 | @@ -116,7 +129,7 @@ class DistroSeriesPackageCache(SQLBase): |
689 | "Removing binary cache for '%s' (%s)" |
690 | % (cache.name, cache.id) |
691 | ) |
692 | - cache.destroySelf() |
693 | + IStore(cache).remove(cache) |
694 | |
695 | @classmethod |
696 | def _update(cls, distroseries, binarypackagenames, archive, log): |
697 | @@ -177,7 +190,7 @@ class DistroSeriesPackageCache(SQLBase): |
698 | cls, |
699 | cls.distroseries == distroseries, |
700 | cls.archive == archive, |
701 | - cls.binarypackagenameID.is_in( |
702 | + cls.binarypackagename_id.is_in( |
703 | [bpn.id for bpn in binarypackagenames] |
704 | ), |
705 | ) |
LGTM 👍