From 48dfdfc3f36f3474ccd92896defd300b4285cc84 Mon Sep 17 00:00:00 2001 From: Roger Ostrander Date: Fri, 19 Jul 2013 15:31:56 -0700 Subject: [PATCH] Domainban: Stop depending on zookeeper --- r2/r2/lib/app_globals.py | 6 +----- r2/r2/models/account.py | 21 ++++++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index db21e3183..f06c152c2 100755 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -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 diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index 46935eccc..20fdf32f1 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -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