Commit b3ec9f60 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Set the id in the insertion job

parent c95d8c06
...@@ -40,7 +40,6 @@ class QueryListener(private val context: Context) : QueryListener { ...@@ -40,7 +40,6 @@ class QueryListener(private val context: Context) : QueryListener {
// Query -> Has already been inserted // Query -> Has already been inserted
private var doneQueries = mutableMapOf<DnsQuery, Boolean>() private var doneQueries = mutableMapOf<DnsQuery, Boolean>()
private val askedServer: String private val askedServer: String
private var nextQueryId = 0L
var lastDnsResponse: DnsMessage? = null var lastDnsResponse: DnsMessage? = null
private val databaseWriteJob: Job private val databaseWriteJob: Job
...@@ -53,7 +52,6 @@ class QueryListener(private val context: Context) : QueryListener { ...@@ -53,7 +52,6 @@ class QueryListener(private val context: Context) : QueryListener {
false false
) )
} }
nextQueryId = context.getDatabase().dnsQueryDao().getLastInsertedId() + 1
databaseWriteJob = databaseWriteJob =
GlobalScope.launch(newSingleThreadContext("QueryListener-DatabaseWrite")) { GlobalScope.launch(newSingleThreadContext("QueryListener-DatabaseWrite")) {
while (isActive) { while (isActive) {
...@@ -77,7 +75,6 @@ class QueryListener(private val context: Context) : QueryListener { ...@@ -77,7 +75,6 @@ class QueryListener(private val context: Context) : QueryListener {
responses = mutableListOf() responses = mutableListOf()
) )
synchronized(waitingQueryLogs) { synchronized(waitingQueryLogs) {
query.id = nextQueryId++
waitingQueryLogs[questionMessage.id] = query waitingQueryLogs[questionMessage.id] = query
queryLogState[questionMessage.id] = false queryLogState[questionMessage.id] = false
} }
...@@ -138,11 +135,13 @@ class QueryListener(private val context: Context) : QueryListener { ...@@ -138,11 +135,13 @@ class QueryListener(private val context: Context) : QueryListener {
} }
val database = context.getDatabase() val database = context.getDatabase()
val dao = database.dnsQueryDao() val dao = database.dnsQueryDao()
var nextQueryId = context.getDatabase().dnsQueryDao().getLastInsertedId() + 1
database.runInTransaction { database.runInTransaction {
currentInsertions.forEach { (key, value) -> currentInsertions.forEach { (key, value) ->
when (queryLogState[key]) { when (queryLogState[key]) {
true -> { true -> {
value.id = nextQueryId++
dao.insert(value) dao.insert(value)
queryLogState[key] = true queryLogState[key] = true
} }
...@@ -151,7 +150,10 @@ class QueryListener(private val context: Context) : QueryListener { ...@@ -151,7 +150,10 @@ class QueryListener(private val context: Context) : QueryListener {
} }
currentDoneInsertions.forEach { (key, value) -> currentDoneInsertions.forEach { (key, value) ->
if (value) dao.update(key) if (value) dao.update(key)
else dao.insert(key) else {
key.id = nextQueryId++
dao.insert(key)
}
} }
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment