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

Simply delete all rules when no sources are given

parent 8395b9d3
...@@ -48,8 +48,8 @@ interface DnsRuleDao { ...@@ -48,8 +48,8 @@ interface DnsRuleDao {
@Query("DELETE FROM DnsRule WHERE importedFrom IS NOT NULL") @Query("DELETE FROM DnsRule WHERE importedFrom IS NOT NULL")
fun deleteAllNonUserRules() fun deleteAllNonUserRules()
@Query("UPDATE DnsRule SET stagingType=1 WHERE importedFrom IS NOT NULL AND stagingType=0") @Query("UPDATE DnsRule SET stagingType=1 WHERE importedFrom IS NOT NULL AND stagingType=0 AND importedFrom IN(:sources)")
fun markNonUserRulesForDeletion() fun markNonUserRulesForDeletion(sources:List<Long>)
@Query("UPDATE DnsRule SET stagingType=0 WHERE importedFrom=:hostSourceId AND stagingType=1") @Query("UPDATE DnsRule SET stagingType=0 WHERE importedFrom=:hostSourceId AND stagingType=1")
fun unstageRulesOfSource(hostSourceId:Long) fun unstageRulesOfSource(hostSourceId:Long)
......
...@@ -174,8 +174,12 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -174,8 +174,12 @@ class RuleImportService : IntentService("RuleImportService") {
private fun startWork() { private fun startWork() {
val dnsRuleDao = getDatabase().dnsRuleDao() val dnsRuleDao = getDatabase().dnsRuleDao()
dnsRuleDao.markNonUserRulesForDeletion() // Stage all, ignoring if the source is actually processed in this run if(sourcesIds.isEmpty()) {
dnsRuleDao.deleteStagedRules() dnsRuleDao.deleteAllNonUserRules()
} else {
dnsRuleDao.markNonUserRulesForDeletion(sourcesIds) // Stage all, ignoring if the source is actually processed in this run
dnsRuleDao.deleteStagedRules()
}
var count = 0 var count = 0
val newChecksums = mutableMapOf<HostSource, String>() val newChecksums = mutableMapOf<HostSource, String>()
sources.forEach { sources.forEach {
...@@ -242,11 +246,13 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -242,11 +246,13 @@ class RuleImportService : IntentService("RuleImportService") {
} }
if (!isAborted) { if (!isAborted) {
updateNotificationFinishing() updateNotificationFinishing()
log("Delete rules staged for deletion") if(sourcesIds.isNotEmpty()) {
dnsRuleDao.deleteMarkedRules() log("Delete rules staged for deletion")
log("Committing staging") dnsRuleDao.deleteMarkedRules()
dnsRuleDao.commitStaging() log("Committing staging")
dnsRuleDao.deleteStagedRules() dnsRuleDao.commitStaging()
dnsRuleDao.deleteStagedRules()
}
log("Recreating database indices") log("Recreating database indices")
getDatabase().recreateDnsRuleIndizes() getDatabase().recreateDnsRuleIndizes()
log("Updating Etag values for sources") log("Updating Etag values for sources")
......
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