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
=== modified file 'src/oopstools/oops/models.py'
--- src/oopstools/oops/models.py 2011-11-21 04:50:37 +0000
+++ src/oopstools/oops/models.py 2011-12-08 05:01:24 +0000
@@ -129,14 +129,20 @@
129 def prune_unreferenced(klass, prune_from, prune_until, references):129 def prune_unreferenced(klass, prune_from, prune_until, references):
130 # XXX: This trusts date more than we may want to - should consider130 # XXX: This trusts date more than we may want to - should consider
131 # having a date_received separate to the date generated.131 # having a date_received separate to the date generated.
132 to_delete = set(Oops.objects.filter(132 while True:
133 date__gte=prune_from, date__lte=prune_until).exclude(133 # There may be very many OOPS to prune, so only ask for a few at a
134 oopsid__in=references))134 # time. This prevents running out of memory in the prune process
135 # deleting 1 at a time is a lot of commits, but leaves the DB lively135 # (can happen when millions of reports are being pruned at once).
136 # for other transactions. May need to batch this in future if its136 to_delete = set(Oops.objects.filter(
137 # too slow.137 date__gte=prune_from, date__lte=prune_until).exclude(
138 for oopsid in to_delete:138 oopsid__in=references)[:10000])
139 Oops.objects.filter(oopsid__exact=oopsid).delete()139 # deleting 1 at a time is a lot of commits, but leaves the DB lively
140 # for other transactions. May need to batch this in future if its
141 # too slow.
142 for oopsid in to_delete:
143 Oops.objects.filter(oopsid__exact=oopsid).delete()
144 if not to_delete:
145 break
140146
141147
142class Report(models.Model):148class Report(models.Model):

Subscribers

People subscribed via source and target branches

to all changes: