Domainban: Stop depending on zookeeper

This commit is contained in:
Roger Ostrander
2013-07-19 15:31:56 -07:00
committed by Neil Williams
parent d0463930f4
commit 48dfdfc3f3
2 changed files with 7 additions and 20 deletions

View File

@@ -60,7 +60,6 @@ from r2.lib.plugin import PluginLoader
from r2.lib.stats import Stats, CacheStats, StatsCollectingConnectionPool
from r2.lib.translation import get_active_langs, I18N_PATH
from r2.lib.utils import config_gold_price, thread_dump
from r2.lib.zookeeper import LiveDict
LIVE_CONFIG_NODE = "/config/live"
@@ -415,16 +414,13 @@ class Globals(object):
self.throttles = LiveList(self.zookeeper, "/throttles",
map_fn=ipaddress.ip_network,
reduce_fn=ipaddress.collapse_addresses)
self.banned_domains = LiveDict(self.zookeeper,
"/banned-domains",
watch=True)
else:
self.zookeeper = None
parser = ConfigParser.RawConfigParser()
parser.read([self.config["__file__"]])
self.live_config = extract_live_config(parser, self.plugins)
self.throttles = tuple() # immutable since it's not real
self.banned_domains = dict()
self.startup_timer.intermediate("zookeeper")
################# MEMCACHE

View File

@@ -31,7 +31,6 @@ from r2.lib.utils import constant_time_compare, canonicalize_email
from r2.lib.cache import sgm
from r2.lib import filters
from r2.lib.log import log_text
from r2.lib.zookeeper import LiveDict
from r2.models.last_modified import LastModified
from pylons import c, g, request
@@ -539,21 +538,13 @@ class Account(Thing):
canons_by_domain.setdefault(domain, [])
canons_by_domain[domain].append(canon)
# Now, build a list of subdomains to check for ban status; for
# abc@foo.bar.com, we need to check foo.bar.com, bar.com, and .com
canons_by_subdomain = {}
for domain, canons in canons_by_domain.iteritems():
parts = domain.rstrip(".").split(".")
while len(parts) >= 1:
whole = ".".join(parts)
canons_by_subdomain.setdefault(whole, [])
canons_by_subdomain[whole].extend(canons)
parts.pop(0)
# Hand off to the domain ban system; it knows in the case of
# abc@foo.bar.com to check foo.bar.com, bar.com, and .com
from r2.models.admintools import bans_for_domain_parts
for subdomain, d in g.banned_domains.iteritems():
if(d and d.get("no_email", None) and
subdomain in canons_by_subdomain):
for canon in canons_by_subdomain[subdomain]:
for domain, canons in canons_by_domain.iteritems():
for d in bans_for_domain_parts(domain):
if d.no_email:
rv[canon] = "domain"
return rv