Merge lp:~lifeless/python-oops-tools/prune into lp:python-oops-tools

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: 25
Merged at revision: 26
Proposed branch: lp:~lifeless/python-oops-tools/prune
Merge into: lp:python-oops-tools
Diff against target: 32 lines (+14/-8)
1 file modified
src/oopstools/oops/models.py (+14/-8)
To merge this branch: bzr merge lp:~lifeless/python-oops-tools/prune
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+84892@code.launchpad.net

Commit message

Pruning too many oopses at once makes django orm sad.

Description of the change

Pruning too many oopses at once makes django orm sad.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/oopstools/oops/models.py'
2--- src/oopstools/oops/models.py 2011-11-21 04:50:37 +0000
3+++ src/oopstools/oops/models.py 2011-12-08 05:01:24 +0000
4@@ -129,14 +129,20 @@
5 def prune_unreferenced(klass, prune_from, prune_until, references):
6 # XXX: This trusts date more than we may want to - should consider
7 # having a date_received separate to the date generated.
8- to_delete = set(Oops.objects.filter(
9- date__gte=prune_from, date__lte=prune_until).exclude(
10- oopsid__in=references))
11- # deleting 1 at a time is a lot of commits, but leaves the DB lively
12- # for other transactions. May need to batch this in future if its
13- # too slow.
14- for oopsid in to_delete:
15- Oops.objects.filter(oopsid__exact=oopsid).delete()
16+ while True:
17+ # There may be very many OOPS to prune, so only ask for a few at a
18+ # time. This prevents running out of memory in the prune process
19+ # (can happen when millions of reports are being pruned at once).
20+ to_delete = set(Oops.objects.filter(
21+ date__gte=prune_from, date__lte=prune_until).exclude(
22+ oopsid__in=references)[:10000])
23+ # deleting 1 at a time is a lot of commits, but leaves the DB lively
24+ # for other transactions. May need to batch this in future if its
25+ # too slow.
26+ for oopsid in to_delete:
27+ Oops.objects.filter(oopsid__exact=oopsid).delete()
28+ if not to_delete:
29+ break
30
31
32 class Report(models.Model):

Subscribers

People subscribed via source and target branches

to all changes: