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

Don't cascade deletion of host sources, instead delete the rules async

parent 91e96a9f
Pipeline #4800 passed with stage
in 50 seconds
......@@ -84,6 +84,7 @@ class DnsRuleActivity : BaseActivity() {
val pos = sourceAdapterList.indexOf(it)
sourceAdapterList.removeAt(pos)
sourceAdapter.notifyItemRemoved(pos)
getDatabase().dnsRuleRepository().deleteAllFromSourceAsync(it)
getDatabase().hostSourceRepository().deleteAsync(it)
dialog.dismiss()
}, getString(R.string.all_no) to { dialog, _ ->
......
......@@ -53,4 +53,7 @@ interface DnsRuleDao {
@Query("SELECT target FROM DnsRule WHERE host=:host AND type = :type LIMIT 1")
fun findRuleTarget(host:String, type:Record.TYPE):String?
@Query("DELETE FROM DnsRule WHERE importedFrom=:sourceId")
fun deleteAllFromSource(sourceId: Long)
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ import org.minidns.record.Record
entity = HostSource::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("importedFrom"),
onDelete = ForeignKey.CASCADE
onDelete = ForeignKey.NO_ACTION
)],
indices = [Index("importedFrom"), Index("host"), Index("host", "type")]
)
......
......@@ -2,26 +2,27 @@ package com.frostnerd.smokescreen.database.repository
import com.frostnerd.smokescreen.database.dao.DnsQueryDao
import com.frostnerd.smokescreen.database.dao.DnsRuleDao
import com.frostnerd.smokescreen.database.entities.HostSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class DnsRuleRepository(val dnsRuleDao: DnsRuleDao) {
......@@ -31,4 +32,10 @@ class DnsRuleRepository(val dnsRuleDao: DnsRuleDao) {
dnsRuleDao.deleteAll()
}
}
fun deleteAllFromSourceAsync(hostSource: HostSource, coroutineScope: CoroutineScope = GlobalScope) {
coroutineScope.launch {
dnsRuleDao.deleteAllFromSource(hostSource.id)
}
}
}
\ No newline at end of file
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