Skip to content
Browse files

Randomly assign comment tree implementation to new links.

  • Loading branch information...
1 parent c5d1a4f commit 2868e6590a22f5fec26eeb4f2ec9ec09d0fc929a Logan Hanks committed
Showing with 24 additions and 1 deletion.
  1. +3 −0 r2/example.ini
  2. +3 −0 r2/r2/lib/app_globals.py
  3. +18 −1 r2/r2/models/link.py
View
3 r2/example.ini
@@ -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
3 r2/r2/lib/app_globals.py
@@ -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
19 r2/r2/models/link.py
@@ -123,6 +123,23 @@ def resubmit_link(self, sr_url=False):
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 @@ 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:

0 comments on commit 2868e65

Please sign in to comment.
Something went wrong with that request. Please try again.