我正在尝试从sql获取50.000个数据,但这需要超过15分钟。如何提高性能并获得少于5分钟的50k数据
while ((items = api.ws_getItems(ITEM_THRESHOLD, lastId, lastDate)).size() > 0)
{
db.beginTransactionNonExclusive();
for (Item i : items)
{
i.save(db);
++curr;
saving(msg, curr, numOfItems,mContext,mProgress);
}
db.setTransactionSuccessful();
db.endTransaction();
lastId = items.get(items.size() - 1).getId();
lastDate =items.get(items.size()-1).getLastSync();
if (items.size() < ITEM_THRESHOLD)
break;
}
/**
* saves current Item in database
* @param db database instance
*/
public void save(SQLiteDatabase db) {
if(db.update(TABLE_NAME, getContentValues(), COL_CODE + "=?", new String[]{code})==0){
db.insert(TABLE_NAME, COL_BARCODE, getContentValues());
}
}