From 155342f59191f0ba61404293f64e90c930b9087b Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Fri, 28 Nov 2014 14:59:10 -0800 Subject: [PATCH] stylesheets: Remove dynamic stylesheet serving. Since the introduction of the media providers and the default installation of the filesystem media provider, it's no longer necessary for local / non-AWS installs to use dynamically served stylesheets. This patch removes that option to reduce complexity in the stylesheet flows. --- r2/example.ini | 2 -- r2/r2/controllers/front.py | 52 +++++++------------------------------- r2/r2/lib/app_globals.py | 1 - r2/r2/lib/pages/pages.py | 4 --- r2/r2/models/subreddit.py | 52 ++++---------------------------------- 5 files changed, 14 insertions(+), 97 deletions(-) diff --git a/r2/example.ini b/r2/example.ini index e8e5e2e51..61b5be5e5 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -95,8 +95,6 @@ lounge_reddit = # if set, this is the domain used for static files served over http and https # if not set, no domain will be specified and relative local URLs will be used instead static_domain = -# whether or not to put subreddit stylesheets in the media system or serve dynamically -subreddit_stylesheets_static = false #### Ops # if your webserver is a proxy and on a different instance on the same 10.0.0.0/8 network diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 28477ef5a..6df7a6e5b 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -62,7 +62,7 @@ from r2.lib.errors import errors, ForbiddenError from listingcontroller import ListingController from oauth2 import require_oauth2_scope from api_docs import api_doc, api_section -from pylons import c, request, response +from pylons import c, request from r2.models.token import EmailVerificationToken from r2.controllers.ipn import generate_blob, validate_blob, GoldException @@ -450,48 +450,20 @@ class FrontController(RedditController): @require_oauth2_scope("modconfig") @api_doc(api_section.moderation, uses_site=True) def GET_stylesheet(self): - """Get the subreddit's current stylesheet. - - This will return either the content of or a redirect to the subreddit's - current stylesheet if one exists. + """Redirect to the subreddit's stylesheet if one exists. See also: [/api/subreddit_stylesheet](#POST_api_subreddit_stylesheet). """ - if g.css_killswitch: - self.abort404() - - # de-stale the subreddit object so we don't poison nginx's cache + # de-stale the subreddit object so we don't poison downstream caches if not isinstance(c.site, FakeSubreddit): c.site = Subreddit._byID(c.site._id, data=True, stale=False) - if c.site.stylesheet_url_http: - url = Reddit.get_subreddit_stylesheet_url(c.site) - if url: - return self.redirect(url) - else: - self.abort404() - - if not c.secure: - stylesheet_contents = c.site.stylesheet_contents + url = Reddit.get_subreddit_stylesheet_url(c.site) + if url: + return self.redirect(url) else: - stylesheet_contents = c.site.stylesheet_contents_secure - - if stylesheet_contents: - if c.site.stylesheet_modified: - self.abort_if_not_modified( - c.site.stylesheet_modified, - private=False, - max_age=timedelta(days=7), - must_revalidate=False, - ) - - response.content_type = 'text/css' - if c.site.type == 'private': - response.headers['X-Private-Subreddit'] = 'private' - return stylesheet_contents - else: - return self.abort404() + self.abort404() def _make_moderationlog(self, srs, num, after, reverse, count, mod=None, action=None): query = Subreddit.get_modactions(srs, mod=mod, action=action) @@ -685,20 +657,14 @@ class FrontController(RedditController): elif (location == 'stylesheet' and c.site.can_change_stylesheet(c.user) and not g.css_killswitch): - if hasattr(c.site,'stylesheet_contents_user') and c.site.stylesheet_contents_user: - stylesheet_contents = c.site.stylesheet_contents_user - elif hasattr(c.site,'stylesheet_contents') and c.site.stylesheet_contents: - stylesheet_contents = c.site.stylesheet_contents - else: - stylesheet_contents = '' + stylesheet_contents = c.site.fetch_stylesheet_source() c.allow_styles = True pane = SubredditStylesheet(site=c.site, stylesheet_contents=stylesheet_contents) elif (location == 'stylesheet' and c.site.can_view(c.user) and not g.css_killswitch): - stylesheet = (c.site.stylesheet_contents_user or - c.site.stylesheet_contents) + stylesheet = c.site.fetch_stylesheet_source() pane = SubredditStylesheetSource(stylesheet_contents=stylesheet) elif (location == 'traffic' and (c.site.public_traffic or diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index 2a26f12b3..9c59fcddd 100644 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -218,7 +218,6 @@ class Globals(object): 'trust_local_proxies', 'shard_link_vote_queues', 'shard_commentstree_queues', - 'subreddit_stylesheets_static', 'ENFORCE_RATELIMIT', 'RL_SITEWIDE_ENABLED', 'RL_OAUTH_SITEWIDE_ENABLED', diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index e459e15c2..ad0ccc745 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -358,13 +358,9 @@ class Reddit(Templated): if c.secure: if sr.stylesheet_url_https: return sr.stylesheet_url_https - elif sr.stylesheet_contents_secure: - return sr.stylesheet_url else: if sr.stylesheet_url_http: return sr.stylesheet_url_http - elif sr.stylesheet_contents: - return sr.stylesheet_url def wiki_actions_menu(self, moderator=False): buttons = [] diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index cdeecbbcc..c6a5b5add 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -25,7 +25,6 @@ from __future__ import with_statement import base64 import collections import datetime -import hashlib import itertools import json @@ -113,7 +112,6 @@ class BaseSite(object): _defaults = dict( static_path=g.static_path, stylesheet=None, - stylesheet_hash='', header=None, header_title='', ) @@ -200,13 +198,6 @@ class BaseSite(object): def get_live_promos(self): raise NotImplementedError - @property - def stylesheet_url(self): - from r2.lib.template_helpers import get_domain - return "//%s/stylesheet.css?v=%s" % (get_domain(cname=False, - subreddit=True), - self.stylesheet_hash) - class SubredditExists(Exception): pass @@ -216,9 +207,6 @@ class Subreddit(Thing, Printable, BaseSite): # attribute, even on a cname. So c.site.static_path should always be # the same as g.static_path. _defaults = dict(BaseSite._defaults, - stylesheet_contents='', - stylesheet_contents_secure='', - stylesheet_modified=None, stylesheet_url_http="", stylesheet_url_https="", header_size=None, @@ -434,12 +422,11 @@ class Subreddit(Thing, Printable, BaseSite): (r._thing2_id, r.get_permissions()) for r in self.each_moderator_invite()) - @property - def stylesheet_contents_user(self): + def fetch_stylesheet_source(self): try: return WikiPage.get(self, 'config/stylesheet')._get('content','') except tdb_cassandra.NotFound: - return self._t.get('stylesheet_contents_user') + return "" @property def prev_stylesheet(self): @@ -620,29 +607,12 @@ class Subreddit(Thing, Printable, BaseSite): minified_http, minified_https = parsed if minified_http or minified_https: - if g.subreddit_stylesheets_static: - self.stylesheet_url_http = upload_stylesheet(minified_http) - self.stylesheet_url_https = g.media_provider.convert_to_https( - upload_stylesheet(minified_https)) - self.stylesheet_hash = "" - self.stylesheet_contents = "" - self.stylesheet_contents_secure = "" - self.stylesheet_modified = None - else: - self.stylesheet_url_http = "" - self.stylesheet_url_https = "" - self.stylesheet_hash = hashlib.md5(minified_https).hexdigest() - self.stylesheet_contents = minified_http - self.stylesheet_contents_secure = minified_https - self.stylesheet_modified = datetime.datetime.now(g.tz) + self.stylesheet_url_http = upload_stylesheet(minified_http) + self.stylesheet_url_https = g.media_provider.convert_to_https( + upload_stylesheet(minified_https)) else: self.stylesheet_url_http = "" self.stylesheet_url_https = "" - self.stylesheet_contents = "" - self.stylesheet_contents_secure = "" - self.stylesheet_hash = "" - self.stylesheet_modified = datetime.datetime.now(g.tz) - self.stylesheet_contents_user = "" # reads from wiki; ensure pg clean self._commit() ModAction.create(self, c.user, action='wikirevise', details='Updated subreddit stylesheet') @@ -1354,14 +1324,6 @@ class DefaultSR(_DefaultSR): def header_size(self): return (self._base and self._base.header_size) or None - @property - def stylesheet_contents(self): - return self._base.stylesheet_contents if self._base else "" - - @property - def stylesheet_contents_secure(self): - return self._base.stylesheet_contents_secure if self._base else "" - @property def stylesheet_url_http(self): return self._base.stylesheet_url_http if self._base else "" @@ -1370,10 +1332,6 @@ class DefaultSR(_DefaultSR): def stylesheet_url_https(self): return self._base.stylesheet_url_https if self._base else "" - @property - def stylesheet_hash(self): - return self._base.stylesheet_hash if self._base else "" - def get_all_comments(self): from r2.lib.db.queries import get_sr_comments, merge_results srs = Subreddit.user_subreddits(c.user, ids=False)