Avoid creating a large SQL by making the patterns an ad-hoc table
Michele Guerini Rocco 2021-09-05 23:59:12 +02:00
parent 217530d113
commit 4765002beb
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
1 changed files with 13 additions and 6 deletions

19
Main.hs
View File

@ -143,14 +143,21 @@ deleteQuotaOrigins = do
quota <- S.select quotaOrigins
S.restrict (by whitelist quota)
return (quota ! #origin)
n <- S.deleteFrom quotaOrigins (by whitelist)
return (n, nub bad)
when (not dry) $
S.deleteFrom_ quotaOrigins (by whitelist)
return (length bad, nub bad)
where
-- check if x ∉ set
by set x = S.not_ . any_ . map (S.like (x ! #origin)) $ set
-- check if quota is not whitelisted
by whitelist quota = S.not_ (S.true `S.isIn` matches)
where
url = quota ! #origin
matches = do
pattern <- S.selectValues (map S.Only whitelist)
S.restrict (url `S.like` S.the pattern)
return S.true
-- turns domains into patterns to match a url
pattern domain = S.text ("http%://%" <> domain <> "/")
any_ = foldl' (.||) S.false
pattern domain = "http%://%" <> domain <> "/"
-- | Deletes per-domain files under the IndexedDB directory