From 36ed3fe2480df384770d4fbff15dbe4d33b69911 Mon Sep 17 00:00:00 2001 From: ketralnis Date: Wed, 13 May 2009 14:38:46 -0700 Subject: [PATCH] Don't show very young links on the new page, so that the thumbnail fetcher et al have had time to act on them --- r2/example.ini | 1 + r2/r2/controllers/listingcontroller.py | 30 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/r2/example.ini b/r2/example.ini index 2f94be872..3699a93cd 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -125,6 +125,7 @@ HOT_PAGE_AGE = 1 # media_period = 10 minutes rising_period = 12 hours +new_incubation = 90 seconds # time of ratelimit purgatory (min) RATELIMIT = 10 diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index f4655a326..a198667c9 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -34,7 +34,7 @@ from r2.lib.db import queries from r2.lib.strings import Score from r2.lib import organic from r2.lib.solrsearch import SearchQuery -from r2.lib.utils import iters, check_cheating +from r2.lib.utils import iters, check_cheating, timeago from r2.lib import sup from admin import admin_profile_query @@ -127,10 +127,14 @@ class ListingController(RedditController): after = self.after, count = self.count, reverse = self.reverse, + keep_fn = self.keep_fn(), wrap = self.builder_wrapper) return b + def keep_fn(self): + return None + def listing(self): """Listing to generate from the builder""" listing = LinkListing(self.builder_obj, show_nums = self.show_nums) @@ -279,12 +283,34 @@ class NewController(ListingController): def menus(self): return [NewMenu(default = self.sort)] + def keep_fn(self): + def keep(item): + """Avoid showing links that are too young, to give time + for things like the spam filter and thumbnail fetcher to + act on them before releasing them into the wild""" + wouldkeep = item.keep_item(item) + if c.user_is_loggedin and (c.user_is_admin or item.subreddit.is_moderator(c.user)): + # let admins and moderators see them regardless + return wouldkeep + elif wouldkeep and c.user_is_loggedin and c.user._id == item.author_id: + # also let the author of the link see them + return True + elif item._date > timeago(g.new_incubation): + # it's too young to show yet + return False + else: + # otherwise, fall back to the regular logic (don't + # show hidden links, etc) + return wouldkeep + + return keep + def query(self): if self.sort == 'rising': return get_rising(c.site) else: return c.site.get_links('new', 'all') - + @validate(sort = VMenu('controller', NewMenu)) def GET_listing(self, sort, **env): self.sort = sort