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

Commit

Permalink
Subreddit._by_name: Use g.gencache
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed Jun 20, 2016
1 parent 18fb269 commit c94ea00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions install/setup_mcrouter.sh
Expand Up @@ -78,6 +78,7 @@ if [ ! -f /etc/mcrouter/global.conf ]; then
"geopromo:": "local-pool",
"srpromos:": "local-pool",
"rising:": "local-pool",
"srid:": "local-pool",
},
"wildcard": {
"type": "PoolRoute",
Expand Down
6 changes: 3 additions & 3 deletions r2/r2/models/subreddit.py
Expand Up @@ -446,8 +446,8 @@ def _by_name(cls, names, stale=False, _update = False):

if to_fetch:
if not _update:
srids_by_name = g.cache.get_multi(
to_fetch.keys(), prefix='subreddit.byname', stale=True)
srids_by_name = g.gencache.get_multi(
to_fetch.keys(), prefix='srid:', stale=True)
else:
srids_by_name = {}

Expand All @@ -471,7 +471,7 @@ def _by_name(cls, names, stale=False, _update = False):
still_missing = set(srnames) - set(fetched)
fetched.update((name, cls.SRNAME_NOTFOUND) for name in still_missing)

g.cache.set_multi(fetched, prefix='subreddit.byname')
g.gencache.set_multi(fetched, prefix='srid:')

srs = {}
srids = [v for v in srids_by_name.itervalues() if v != cls.SRNAME_NOTFOUND]
Expand Down
6 changes: 3 additions & 3 deletions r2/r2/tests/unit/models/subreddit_test.py
Expand Up @@ -120,7 +120,7 @@ def test_numerics(self):
class ByNameTest(unittest.TestCase):
def setUp(self):
self.cache = MagicMock()
g.cache = self.cache
g.gencache = self.cache

self.subreddit_byID = MagicMock()
Subreddit._byID = self.subreddit_byID
Expand Down Expand Up @@ -226,7 +226,7 @@ def testForceUpdate(self):

self.assertEqual(ret, sr)
self.cache.set_multi.assert_called_once_with(
{sr.name: sr._id}, prefix="subreddit.byname")
{sr.name: sr._id}, prefix="srid:")

def testCacheNegativeResults(self):
self.cache.get_multi.return_value = {}
Expand All @@ -237,7 +237,7 @@ def testCacheNegativeResults(self):
Subreddit._by_name("doesnotexist")

self.cache.set_multi.assert_called_once_with(
{"doesnotexist": Subreddit.SRNAME_NOTFOUND}, prefix="subreddit.byname")
{"doesnotexist": Subreddit.SRNAME_NOTFOUND}, prefix="srid:")

def testExcludeNegativeLookups(self):
self.cache.get_multi.return_value = {"doesnotexist": Subreddit.SRNAME_NOTFOUND}
Expand Down

0 comments on commit c94ea00

Please sign in to comment.