~lifeless/python-oops-tools/bug-1048470

« back to all changes in this revision

Viewing changes to src/oopstools/oops/models.py

  • Committer: Robert Collins
  • Date: 2011-11-21 03:42:03 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: robertc@robertcollins.net-20111121034203-ek437opa2fbjjloq
Implement crude pruning for the DB records. Currently untested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
        return unicode(self.value)
121
121
 
122
122
 
 
123
class PruneInfo(models.Model):
 
124
    """Information about oops pruning."""
 
125
    
 
126
    pruned_until = models.DateTimeField()
 
127
 
 
128
    @classmethod
 
129
    def prune_unreferenced(klass, prune_from, prune_until, references):
 
130
        # XXX: This trusts date more than we may want to - should consider
 
131
        # having a date_received separate to the date generated.
 
132
        to_delete = set(Oops.objects.filter(
 
133
            date__gte=prune_from, date__lte=prune_until).exclude(
 
134
            oopsid__in=references))
 
135
        # deleting 1 at a time is a lot of commits, but leaves the DB lively
 
136
        # for other transactions. May need to batch this in future if its
 
137
        # too slow.
 
138
        for oopsid in to_delete:
 
139
            Oops.objects.filter(oopsid__exact=oopsid).delete()
 
140
 
 
141
 
123
142
class Report(models.Model):
124
143
    """A summary report for OOPSes of a set of prefixes."""
125
144