mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 12:44:38 +00:00
Avoid reallocation inserting logs into database
This commit is contained in:
committed by
Cody Henthorne
parent
57454a2661
commit
7074684474
@@ -160,7 +160,7 @@ class LogDatabase private constructor(
|
||||
private val readableDatabase: SQLiteDatabase get() = openHelper.readableDatabase
|
||||
private val writableDatabase: SQLiteDatabase get() = openHelper.writableDatabase
|
||||
|
||||
fun insert(logs: List<LogEntry>, currentTime: Long) {
|
||||
fun insert(logs: Sequence<LogEntry>, currentTime: Long) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
logs.forEach { log ->
|
||||
db.insertInto(TABLE_NAME)
|
||||
|
||||
@@ -126,7 +126,7 @@ class PersistentLogger private constructor(application: Application) : Log.Logge
|
||||
override fun run() {
|
||||
while (true) {
|
||||
requests.blockForRequests(buffer)
|
||||
db.logs.insert(buffer.flatMap { requestToEntries(it) }, System.currentTimeMillis())
|
||||
db.logs.insert(buffer.asSequence().flatMap { requestToEntries(it) }, System.currentTimeMillis())
|
||||
buffer.clear()
|
||||
requests.notifyFlushed()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user