0

我正在开发一个 android 应用程序,它需要在登录时下载大量有关某些预订的数据。第一个实现是启动一个事务,保存所有预订,并在最后提交事务。这种方法有可观的性能,但副作用是有时用户强行关闭应用程序,导致从那一刻起所有保存的数据丢失。我现在采取的方法是将每个预订保存在事务中(因为每个预订都会影响一些表),但是当有很多预订时,保存所有数据所需的时间有时会超过 15 分钟,这也是很多。有没有什么方法可以帮助我快速完成插入,而无需对所有数据进行事务处理?其实代码是这样的:

for (Booking _booking : bookings) {

            _booking.save();
        }

这是保存方法的伪代码

result=false;
try{
beginTransaction()

insert("table1",ContentValues)
insert("table2",ContentValues)
insert("table3",ContentValues)
insert("table4",ContentValues)

execSQL("SAVEPOINT " + this.bookingCode);
result = true;
}
catch{
execSQL("ROLLBACK TO SAVEPOINT " + lastSavePoint)
}

//this method commits or not depending on the result. I need to commit in any case 
//because i use beginTransactionWithListener in beginTransaction() function
endTransaction(result);
4

0 回答 0