Improve save() statement

瀏覽次數:40 次
跳到第一則未讀訊息

orbis....@gmail.com

未讀,
2014年8月19日 清晨7:57:302014/8/19
收件者: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

未讀,
2014年8月21日 下午2:27:512014/8/21
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息