diff --git a/r2/example.ini b/r2/example.ini index d3df3c32f..869f971d5 100644 --- a/r2/example.ini +++ b/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 diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index 48560daa4..e776ddc99 100755 --- a/r2/r2/lib/app_globals.py +++ b/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): diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index b0d9cdd82..f182acf6f 100755 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -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: