检测忘了SQLite的交易在Android上使用StrictMode?SQLite、Android、StrictMode

2023-09-06 00:38:12 作者:手握风云.

执行多个SQL语句,而不将它们放入一个事务是一个严重的瓶颈(如见 HTTP:/ /www.sqlite.org/faq.html#q19 )。我还没有彻底检查如何SQLite是在Android配置,但有传言称我在更多的地方使用事务处理时感觉戏剧性的性能提升在我的应用程序。

Executing multiple SQL statements without putting them into one transaction is a severe bottleneck (see e.g. http://www.sqlite.org/faq.html#q19). I haven't thoroughly checked how SQLite is configured on Android, but anecdotally I perceived dramatical performance increase within my on app when using transactions in more places.

是否有可能检测情况,其中一个忘记使用StrictMode使用交易?如果不是,可能是考虑StrictMode的未来版本?这可能是有点棘手的检测,但两种不同的策略可能是,1)交易之外的非选择语句,或2)的时间很短的时间内执行的事务之外的多个非SELECT语句。

Is it possible to detect instances where one forgets to use transactions using StrictMode? If not, could that be considered for a future release of StrictMode? It might be somewhat tricky to detect, but two different strategies could be, 1) non-select statements outside transaction, or 2) multiple non-select statements outside transaction executed within a short period of time.

推荐答案

是啊,这听起来像是一件好事来抓。我能想象一个API,如:

Yeah, that sounds like a good thing to catch. I could imagine an API like:

StrictMode.catchWritesOutsideTransactionsOn(SQLiteDatabase分贝);

我们一直在考虑其他的SQLite挂接到StrictMode(大多是围绕选择缺少的指标等等),但是这是一个好主意呢!

We've been considering other SQLite hooks into StrictMode (mostly around selects missing indexes and such), but this is a good idea too!