Randomly assign comment tree implementation to new links.

This commit is contained in:
Logan Hanks
2012-06-20 12:21:44 -07:00
parent c5d1a4fc3e
commit 2868e6590a
3 changed files with 24 additions and 1 deletions

View File

@@ -555,3 +555,6 @@ sr_discovery_links =
spotlight_interest_sub_p = .05
# and for users that have not ever subscribed:
spotlight_interest_nosub_p = .1
# map of comment tree version to how frequently it should be chosen relative to
# the others
comment_tree_version_weights = 1:9, 2:1

View File

@@ -217,6 +217,9 @@ class Globals(object):
'sr_discovery_links',
'fastlane_links',
],
ConfigValue.dict(ConfigValue.int, ConfigValue.float): [
'comment_tree_version_weights',
],
}
def __init__(self, global_conf, app_conf, paths, **extra):

View File

@@ -122,6 +122,23 @@ class Link(Thing, Printable):
submit_url += 'submit?resubmit=true&url=' + url_escape(self.url)
return submit_url
@classmethod
def _choose_comment_tree_version(cls):
try:
weights = g.live_config['comment_tree_version_weights']
except KeyError:
return cls._defaults['comment_tree_version']
total = sum(weights.itervalues())
r = random.random() * total
t = 0
for version, weight in weights.iteritems():
t += weight
if t >= r:
return version
# this point should never be reached, but if it is, return the default
# for old links
return cls._defaults['comment_tree_version']
@classmethod
def _submit(cls, title, url, author, sr, ip, spam=False):
from r2.models import admintools
@@ -134,7 +151,7 @@ class Link(Thing, Printable):
sr_id=sr._id,
lang=sr.lang,
ip=ip,
comment_tree_version=2)
comment_tree_version=cls._choose_comment_tree_version())
l._commit()
l.set_url_cache()
if author._spam: