Skip to content

Commit

Permalink
Moved logic for handling extra calls to dedicated class "OneOffDelegate"
Browse files Browse the repository at this point in the history
*This commit is related to issue #529 [1]*

[1] #529
  • Loading branch information
JaniruTEC committed Apr 22, 2024
1 parent 0e63cad commit 9f70454
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,11 @@ internal class MappingSupportSQLiteDatabase(
private val delegateQuery: SupportSQLiteQuery
) : SupportSQLiteQuery by delegateQuery {

private val lock = Any()
private var called = false

private val _sql = map(delegateQuery.sql)
private val sqlDelegate = OneOffDelegate { Timber.tag("MappingSupportSQLiteQuery").e("SQL queried twice") }

override val sql: String
get() = synchronized(lock) {
if (called) {
Timber.tag("MappingSupportSQLiteQuery").e("SQL queried twice")
}
called = true
return _sql
}
get() = sqlDelegate.call { _sql }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.cryptomator.data.db.sqlmapping

internal class OneOffDelegate(private val beforeExtraCalls: () -> Unit) {

private val lock = Any()
private var called = false

fun <R> call(delegateCallable: () -> R): R = synchronized(lock) {
if (called) {
beforeExtraCalls()
}
called = true
return delegateCallable()
}
}

0 comments on commit 9f70454

Please sign in to comment.