Skip to content
Snippets Groups Projects
Commit da11bb38 authored by Gandalf's avatar Gandalf
Browse files

[JES] Update to the mutes checks. Don't clear the cache every hour, instead...

[JES] Update to the mutes checks. Don't clear the cache every hour, instead simply remove a user from it if it's detected that they have been removed from the blacklists
parent 7d5854cf
No related branches found
No related tags found
5 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!16Dk issue 3 concurrent block query rebase,!15Dk issue 3 concurrent block query
...@@ -44,7 +44,6 @@ class Mutes: ...@@ -44,7 +44,6 @@ class Mutes:
self.accounts = set(_read_url(self.url).decode('utf8').split()) self.accounts = set(_read_url(self.url).decode('utf8').split())
jsn = _read_url(self.blacklist_api_url + "/blacklists") jsn = _read_url(self.blacklist_api_url + "/blacklists")
self.blist = set(json.loads(jsn)) self.blist = set(json.loads(jsn))
self.blist_map = dict()
log.warning("%d muted, %d blacklisted", len(self.accounts), len(self.blist)) log.warning("%d muted, %d blacklisted", len(self.accounts), len(self.blist))
self.fetched = perf() self.fetched = perf()
...@@ -63,22 +62,27 @@ class Mutes: ...@@ -63,22 +62,27 @@ class Mutes:
if perf() - inst.fetched > 3600: if perf() - inst.fetched > 3600:
inst.load() inst.load()
if name not in inst.blist_map: if name not in inst.blist and name not in inst.accounts:
out = [] if name in inst.blist_map: #this user was blacklisted, but has been removed from the blacklists since the last check
if name in inst.blist: inst.blist_map.pop(name) #so just pop them from the cache
url = "%s/user/%s" % (inst.blacklist_api_url, name) return []
lists = json.loads(_read_url(url)) else: # user is on at least 1 list
out.extend(lists['blacklisted']) blacklists_for_user = []
if name not in inst.blist_map: #user has been added to a blacklist since the last check so figure out what lists they belong to
if name in inst.accounts: if name in inst.blist: #blacklisted accounts
if 'irredeemables' not in out: url = "%s/user/%s" % (inst.blacklist_api_url, name)
out.append('irredeemables') lists = json.loads(_read_url(url))
blacklists_for_user.extend(lists['blacklisted'])
if int(rep) < 1:
out.append('reputation-0') if name in inst.accounts: #muted accounts
elif int(rep) == 1: if 'irredeemables' not in blacklists_for_user:
out.append('reputation-1') blacklists_for_user.append('irredeemables')
inst.blist_map[name] = out if int(rep) < 1:
blacklists_for_user.append('reputation-0') #bad reputation
return inst.blist_map[name] if int(rep) == 1:
blacklists_for_user.append('reputation-1') #bad reputation
inst.blist_map[name] = blacklists_for_user
return inst.blist_map[name]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment