Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Randomly assign comment tree implementation to new links.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Hanks committed Nov 20, 2012
1 parent c5d1a4f commit 2868e65
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions r2/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions r2/r2/lib/app_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 18 additions & 1 deletion r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def resubmit_link(self, sr_url=False):
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
Expand All @@ -134,7 +151,7 @@ def _submit(cls, title, url, author, sr, ip, spam=False):
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:
Expand Down

0 comments on commit 2868e65

Please sign in to comment.