[CentralOH] Django Management Command Memory Usage
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Tue Jun 5 22:55:04 CEST 2012
On Mon, 4 Jun 2012 10:39:37 -0400, Kurtis Mullins <kurtis.mullins at gmail.com> wrote:
> It looks like you've got the fat trimmed off this one about as much as you
> can.
I found a way. Using pre_save stuff elsewhere, I trimmed some more:
def handle(self, *args, **options):
for record in Places.objects.all():
record.save()
django.db.connection.close()
Yup. It's so trim now it looks like I forgot something.
The ugly chunky version is:
def handle(self, *args, **options):
chunk = 100000
min_id = Places.objects.all().aggregate(Min('id'))['id__min']
max_id = Places.objects.all().aggregate(Max('id'))['id__max']
for j in xrange(min_id, max_id + 1, chunk):
for record in Places.objects.all().filter(
id__gte=j).filter(id__lt=j + chunk):
record.save()
django.db.connection.close()
pre_save stuff is cool, very cool.
More information about the CentralOH
mailing list