On Sat, Nov 21, 2009 at 7:44 AM, Doug Blank <[email protected]> wrote:
[snip]
> It does seem that:
>
> Table.objects.all().delete()
>
> is "leaking" memory (eg, continues to use memory) and is very slow.
> I'm trying to find a better (faster, less memory) method similar to
> the manage.py command sql_flush...
Is this a "better" way to flush a table, programmatically?
from django.db import connection, transaction
models = [Person, User, ...]
cursor = connection.cursor()
flush_tables = []
for model in models:
flush_tables.append(model._meta.db_table)
statements = connection.ops.sql_flush(no_style(),
flush_tables,
connection.introspection.sequence_list())
for statement in statements:
cursor.execute(statement)
transaction.commit_unless_managed()
It would be nice if flush() were a method on Model, yes?
-Doug
> Thank you very much for the pointer! Part of the problem solved...
>
> -Doug
>
>> See:
>> http://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory
>>
>> Karen
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=.