Skip to content

Commit

Permalink
Simply delete all rules when no sources are given
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch4t4r committed Jun 5, 2021
1 parent 8395b9d commit a06cab1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ interface DnsRuleDao {
@Query("DELETE FROM DnsRule WHERE importedFrom IS NOT NULL")
fun deleteAllNonUserRules()

@Query("UPDATE DnsRule SET stagingType=1 WHERE importedFrom IS NOT NULL AND stagingType=0")
fun markNonUserRulesForDeletion()
@Query("UPDATE DnsRule SET stagingType=1 WHERE importedFrom IS NOT NULL AND stagingType=0 AND importedFrom IN(:sources)")
fun markNonUserRulesForDeletion(sources:List<Long>)

@Query("UPDATE DnsRule SET stagingType=0 WHERE importedFrom=:hostSourceId AND stagingType=1")
fun unstageRulesOfSource(hostSourceId:Long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ class RuleImportService : IntentService("RuleImportService") {

private fun startWork() {
val dnsRuleDao = getDatabase().dnsRuleDao()
dnsRuleDao.markNonUserRulesForDeletion() // Stage all, ignoring if the source is actually processed in this run
dnsRuleDao.deleteStagedRules()
if(sourcesIds.isEmpty()) {
dnsRuleDao.deleteAllNonUserRules()
} else {
dnsRuleDao.markNonUserRulesForDeletion(sourcesIds) // Stage all, ignoring if the source is actually processed in this run
dnsRuleDao.deleteStagedRules()
}
var count = 0
val newChecksums = mutableMapOf<HostSource, String>()
sources.forEach {
Expand Down Expand Up @@ -242,11 +246,13 @@ class RuleImportService : IntentService("RuleImportService") {
}
if (!isAborted) {
updateNotificationFinishing()
log("Delete rules staged for deletion")
dnsRuleDao.deleteMarkedRules()
log("Committing staging")
dnsRuleDao.commitStaging()
dnsRuleDao.deleteStagedRules()
if(sourcesIds.isNotEmpty()) {
log("Delete rules staged for deletion")
dnsRuleDao.deleteMarkedRules()
log("Committing staging")
dnsRuleDao.commitStaging()
dnsRuleDao.deleteStagedRules()
}
log("Recreating database indices")
getDatabase().recreateDnsRuleIndizes()
log("Updating Etag values for sources")
Expand Down

0 comments on commit a06cab1

Please sign in to comment.