Commit 262c83d
Optimize protected_versions() to avoid expensive JOINs
The protected_versions() method was building a single queryset using |= (OR)
operations that caused Django to generate a LEFT OUTER JOIN on core_publication
across all repository versions (10,000+ rows), resulting in queries taking
minutes in large databases.
Rewritten to collect protected version PKs from separate simple queries against
Distribution and Publication tables, then return a simple filter(pk__in=...).
Also defer the content_ids ArrayField in cleanup_old_versions since it can
contain hundreds of thousands of UUIDs per version and is not needed by
version.delete().
fixes: #7594
Assisted By: claude-opus-4.61 parent ac64ff3 commit 262c83d
2 files changed
Lines changed: 28 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
326 | 328 | | |
327 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
328 | 334 | | |
329 | 335 | | |
330 | | - | |
331 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
332 | 342 | | |
333 | 343 | | |
334 | 344 | | |
335 | 345 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
340 | 351 | | |
341 | 352 | | |
342 | 353 | | |
| |||
352 | 363 | | |
353 | 364 | | |
354 | 365 | | |
355 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
356 | 370 | | |
357 | | - | |
| 371 | + | |
358 | 372 | | |
359 | 373 | | |
360 | 374 | | |
| |||
416 | 430 | | |
417 | 431 | | |
418 | 432 | | |
419 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
420 | 436 | | |
421 | 437 | | |
422 | 438 | | |
| |||
0 commit comments