mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-02-07 13:14:54 -05:00
Fix miscellaneous bugs with promoted links, and reduce app-server load
by reducing calls to apy.py:POST_onload
This commit is contained in:
@@ -30,6 +30,8 @@ from r2.models import *
|
||||
from r2.models.subreddit import Default as DefaultSR
|
||||
import r2.models.thing_changes as tc
|
||||
|
||||
from r2.controllers import ListingController
|
||||
|
||||
from r2.lib.utils import get_title, sanitize_url, timeuntil, set_last_modified
|
||||
from r2.lib.utils import query_string, to36, timefromnow
|
||||
from r2.lib.wrapped import Wrapped
|
||||
@@ -59,6 +61,7 @@ from datetime import datetime, timedelta
|
||||
from md5 import md5
|
||||
|
||||
from r2.lib.promote import promote, unpromote, get_promoted
|
||||
from r2.lib.promote import promote_builder_wrapper
|
||||
|
||||
def link_listing_by_url(url, count = None):
|
||||
try:
|
||||
@@ -1283,15 +1286,8 @@ class ApiController(RedditController):
|
||||
mid_margin = VCssMeasure('mid_margin'),
|
||||
links = VFullNames('links'))
|
||||
def POST_fetch_links(self, res, num_margin, mid_margin, links):
|
||||
# TODO: redundant with listingcontroller. Perhaps part of reddit_base or utils
|
||||
def builder_wrapper(thing):
|
||||
if c.user.pref_compress and isinstance(thing, Link):
|
||||
thing.__class__ = LinkCompressed
|
||||
thing.score_fmt = Score.points
|
||||
return Wrapped(thing)
|
||||
|
||||
b = IDBuilder([l._fullname for l in links],
|
||||
wrap = builder_wrapper)
|
||||
wrap = promote_builder_wrapper(ListingController.builder_wrapper))
|
||||
l = OrganicListing(b)
|
||||
l.num_margin = num_margin
|
||||
l.mid_margin = mid_margin
|
||||
@@ -1322,6 +1318,7 @@ class ApiController(RedditController):
|
||||
@Json
|
||||
@validate(VSponsor(),
|
||||
ValidDomain('url'),
|
||||
ip = ValidIP(),
|
||||
l = VLink('link_id'),
|
||||
title = VTitle('title'),
|
||||
url = VUrl(['url', 'sr']),
|
||||
@@ -1332,7 +1329,8 @@ class ApiController(RedditController):
|
||||
timelimit = VBoolean('timelimit'),
|
||||
timelimitlength = VInt('timelimitlength',1,1000),
|
||||
timelimittype = VOneOf('timelimittype',['hours','days','weeks']))
|
||||
def POST_edit_promo(self, res, title, url, sr, subscribers_only,
|
||||
def POST_edit_promo(self, res, ip,
|
||||
title, url, sr, subscribers_only,
|
||||
disable_comments,
|
||||
timelimit = None, timelimitlength = None, timelimittype = None,
|
||||
disable_expire = None,
|
||||
@@ -1375,7 +1373,9 @@ class ApiController(RedditController):
|
||||
l = Link(title = title,
|
||||
url = url,
|
||||
author_id = c.user._id,
|
||||
sr_id = sr._id)
|
||||
sr_id = sr._id,
|
||||
lang = sr.lang,
|
||||
ip = ip)
|
||||
|
||||
if timelimit and timelimitlength and timelimittype:
|
||||
promote_until = timefromnow("%d %s" % (timelimitlength, timelimittype))
|
||||
@@ -1416,10 +1416,8 @@ class ApiController(RedditController):
|
||||
|
||||
|
||||
@Json
|
||||
@validate(ids = nop("ids"))
|
||||
@validate(ids = VLinkFullnames('ids'))
|
||||
def POST_onload(self, res, ids, *a, **kw):
|
||||
ids = set(ids.split(','))
|
||||
|
||||
if not ids:
|
||||
res.object = {}
|
||||
return
|
||||
|
||||
@@ -335,7 +335,7 @@ class ByIDController(ListingController):
|
||||
def GET_listing(self, names, **env):
|
||||
if not names:
|
||||
return self.abort404()
|
||||
self.names = names.split(' ')
|
||||
self.names = names
|
||||
return ListingController.GET_listing(self, **env)
|
||||
|
||||
|
||||
|
||||
@@ -182,16 +182,18 @@ def chksrname(x):
|
||||
|
||||
|
||||
class VLinkFullnames(Validator):
|
||||
"A space- or comma-separated list of fullnames for Links"
|
||||
valid_re = re.compile(r'^(' + Link._type_prefix + str(Link._type_id) +
|
||||
'_[0-9a-z]+ ?)+$')
|
||||
|
||||
r'_[0-9a-z]+[ ,]?)+$')
|
||||
splitter = re.compile('[ ,]+')
|
||||
|
||||
def __init__(self, item, *a, **kw):
|
||||
self.item = item
|
||||
Validator.__init__(self, item, *a, **kw)
|
||||
|
||||
def run(self, val):
|
||||
if val and self.valid_re.match(val):
|
||||
return val
|
||||
return self.splitter.split(val)
|
||||
|
||||
class VLength(Validator):
|
||||
def __init__(self, item, length = 10000,
|
||||
|
||||
@@ -93,10 +93,9 @@ def process_new_links(period = media_period, force = False):
|
||||
results = {}
|
||||
jobs = []
|
||||
for link in fetch_things2(links):
|
||||
if link.is_self:
|
||||
if link.is_self or link.promoted:
|
||||
continue
|
||||
|
||||
if not force and (link.has_thumbnail or link.media_object):
|
||||
elif not force and (link.has_thumbnail or link.media_object):
|
||||
continue
|
||||
|
||||
jobs.append(make_link_info_job(results, link, g.useragent))
|
||||
|
||||
@@ -1178,11 +1178,11 @@ class PromotePage(Reddit):
|
||||
extension_handling = False
|
||||
|
||||
def __init__(self, title, nav_menus = None, *a, **kw):
|
||||
buttons = [NamedButton('current_promos'),
|
||||
buttons = [NamedButton('current_promos', dest = ''),
|
||||
NamedButton('new_promo')]
|
||||
|
||||
menu = NavMenu(buttons, title='show', base_path = '/promote',
|
||||
type='flatlist', default = 'current_promos')
|
||||
type='flatlist')
|
||||
|
||||
if nav_menus:
|
||||
nav_menus.insert(0, menu)
|
||||
|
||||
@@ -104,6 +104,16 @@ Thing.prototype = {
|
||||
show(this.row);
|
||||
}
|
||||
/* promoted magic */
|
||||
if(reddit_thing_info.fetch && reddit_thing_info.fetch.length != 0) {
|
||||
var f = reddit_thing_info.fetch;
|
||||
for(var i = 0; i < f.length; i++) {
|
||||
if (f[i] == this._id) {
|
||||
redditRequest("onload", {ids: f.join(",")},
|
||||
handleOnLoad, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(reddit_thing_info && reddit_thing_info[this._id]) {
|
||||
var img = this.$("promote_img");
|
||||
var img_src = unsafe(reddit_thing_info[this._id][0]);
|
||||
|
||||
@@ -95,7 +95,7 @@ OrganicListing.populate = function(links) {
|
||||
var o = new OrganicListing();
|
||||
for(var i = 0; i < links.length; i++) {
|
||||
d = links[i].data;
|
||||
var t = o.append(unsafe(d.content));
|
||||
var t = o.insert(unsafe(d.content), o.listing.firstChild);
|
||||
if(t && t[0]) {
|
||||
vl[d.id] = d.vl;
|
||||
o.listing._loaded[d.id] = t[0];
|
||||
|
||||
@@ -583,6 +583,11 @@ before enabling */
|
||||
border: solid 1px;
|
||||
padding: 5px 0 5px 0;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.promoted-list {
|
||||
font-size: larger;
|
||||
}
|
||||
|
||||
.organic-listing .promoted {
|
||||
|
||||
@@ -70,24 +70,25 @@ function init() {
|
||||
/* onload populates reddit_link_info, so checking its contents
|
||||
* ensures it doesn't get called on reload/refresh */
|
||||
if ( reddit_thing_info.fetch && reddit_thing_info.fetch.length != 0 )
|
||||
redditRequest("onload", {ids: reddit_thing_info.fetch.join(",")},
|
||||
handleOnLoad);
|
||||
updateLinks(reddit_thing_info.fetch);
|
||||
update_reddit_count();
|
||||
}
|
||||
|
||||
function handleOnLoad(r) {
|
||||
r = parse_response(r);
|
||||
|
||||
var f = reddit_thing_info.fetch;
|
||||
|
||||
reddit_thing_info = (r && r.response) ? r.response.object : {};
|
||||
|
||||
function updateLinks(f) {
|
||||
for (var i = 0; i < f.length; i++) {
|
||||
var l = new Link(f[i]);
|
||||
if (l.row && l.row.style.display != "none")
|
||||
l.show();
|
||||
}
|
||||
}
|
||||
|
||||
function handleOnLoad(r) {
|
||||
r = parse_response(r);
|
||||
var f = reddit_thing_info.fetch;
|
||||
reddit_thing_info.fetch = [];
|
||||
|
||||
reddit_thing_info = (r && r.response) ? r.response.object : {};
|
||||
updateLinks(f);
|
||||
}
|
||||
|
||||
function deletetoggle(link, type) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
from datetime import datetime
|
||||
%>
|
||||
|
||||
<%namespace file="printable.html" import="state_button, yes_no_button" />
|
||||
<%namespace file="printable.html" import="yes_no_button" />
|
||||
<%namespace file="utils.html" import="plain_link" />
|
||||
|
||||
%if thing.a.promoted:
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<div>
|
||||
<h1>${_('current promotions')}</h1>
|
||||
|
||||
<ul>
|
||||
<ul class="promoted-list">
|
||||
%for t in thing.things:
|
||||
<li class="entry">
|
||||
${plain_link(t.title,'/promote/edit_promo/%s' % to36(t._id))}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
from r2.lib.media import thumbnail_url
|
||||
%>
|
||||
<%namespace file="utils.html" import="error_field, checkbox, plain_link, image_upload" />
|
||||
<%namespace file="printable.html" import="state_button, yes_no_button" />
|
||||
<%namespace file="printable.html" import="yes_no_button" />
|
||||
|
||||
<form class="content pretty-form" method="POST" action="/post/new_promo"
|
||||
id="promo_form" onsubmit="return post_form(this, 'edit_promo', null, null, true)">
|
||||
@@ -34,21 +34,6 @@
|
||||
%endif
|
||||
|
||||
<table class="content preftable">
|
||||
%if thing.link:
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
${plain_link("go to the comments page", thing.link.make_permalink_slow())}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
${yes_no_button("unpromote", thing.link._fullname, _("unpromote"), \
|
||||
"return deletetoggle(this,'unpromote');", _("unpromoted"))}
|
||||
</td>
|
||||
</tr>
|
||||
%endif
|
||||
<tr>
|
||||
<th><label for="title">${_("title")}</label></th>
|
||||
<td>
|
||||
@@ -136,6 +121,22 @@
|
||||
<td id="img-status"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="content preftable pretty-form">
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
${plain_link("go to the comments page", thing.link.make_permalink_slow())}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
${yes_no_button("unpromote", thing.link._fullname, _("unpromote"), \
|
||||
"return deletetoggle(this,'unpromote');", _("unpromoted"))}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
%endif
|
||||
|
||||
<div class="save-button">
|
||||
|
||||
Reference in New Issue
Block a user