mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 23:08:22 -05:00
Factor activity fuzzing out of Subreddit.get_accounts_active.
This allows liveupdate to reuse the same code.
This commit is contained in:
@@ -1517,3 +1517,11 @@ def parse_ini_file(config_file):
|
||||
parser.optionxform = str # ensure keys are case-sensitive as expected
|
||||
parser.readfp(config_file)
|
||||
return parser
|
||||
|
||||
|
||||
def fuzz_activity(count):
|
||||
"""Add some jitter to an activity metric to maintain privacy."""
|
||||
# decay constant is e**(-x / 60)
|
||||
decay = math.exp(float(-count) / 60)
|
||||
jitter = round(5 * decay)
|
||||
return count + random.randint(0, jitter)
|
||||
|
||||
@@ -40,7 +40,7 @@ from r2.lib.db.operators import lower, or_, and_, desc
|
||||
from r2.lib.errors import UserRequiredException
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.permissions import ModeratorPermissionSet
|
||||
from r2.lib.utils import tup, last_modified_multi
|
||||
from r2.lib.utils import tup, last_modified_multi, fuzz_activity
|
||||
from r2.lib.utils import timeago, summarize_markdown
|
||||
from r2.lib.cache import sgm
|
||||
from r2.lib.strings import strings, Score
|
||||
@@ -54,8 +54,6 @@ from r2.lib import hooks
|
||||
from r2.models.query_cache import MergedCachedQuery
|
||||
import pycassa
|
||||
|
||||
import math
|
||||
|
||||
from r2.lib.utils import set_last_modified
|
||||
from r2.models.wiki import WikiPage
|
||||
import os.path
|
||||
@@ -403,10 +401,7 @@ class Subreddit(Thing, Printable, BaseSite):
|
||||
fuzzed = True
|
||||
cached_count = g.cache.get(key)
|
||||
if not cached_count:
|
||||
# decay constant is e**(-x / 60)
|
||||
decay = math.exp(float(-count) / 60)
|
||||
jitter = round(5 * decay)
|
||||
count = count + random.randint(0, jitter)
|
||||
count = fuzz_activity(count)
|
||||
g.cache.set(key, count, time=5*60)
|
||||
else:
|
||||
count = cached_count
|
||||
|
||||
Reference in New Issue
Block a user