Improve save() statement

40 views
Skip to first unread message

orbis....@gmail.com

unread,
Aug 19, 2014, 7:57:30 AM8/19/14
to qdj...@googlegroups.com
The following snipnet of code is very slow:


for(int i=0;i<500;i++){
 
MyModel model;
  model
.a=1
  model
.b=2
  model
.c=3
  model
.otherModel=otherModelPointer;
  model
.save();
}


Is there a way to speed up the insert step?

Perhaps by using multiple insert statments in one transaction (db.transaction() and db.commit()) ? But I don't know how to do this in QDjango.

Advise me please ! Thanks

orbis....@gmail.com

unread,
Aug 21, 2014, 2:27:51 PM8/21/14
to qdj...@googlegroups.com

QDjango::database().transaction();

for(int i=0;i<500;i++){
 
MyModel model;
  model
.a=1
  model
.b=2
  model
.c=3
  model
.otherModel=otherModelPointer;
  model
.save();
}
QDjango::database().commit();

solved
Reply all
Reply to author
Forward
0 new messages