cache: Use getattr to access _cache.

`_cache` is not an attribute defined on `BaseCache`, but an
implementation detail of django_bmemcache.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-07-18 18:14:23 -04:00
committed by Tim Abbott
parent beb09cdf38
commit 22ebf701aa
3 changed files with 18 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ import multiprocessing
import os
from mimetypes import guess_type
import bmemcached
from django.conf import settings
from django.core.cache import cache
from django.db import connection
@@ -40,7 +41,9 @@ def transfer_avatars_to_s3(processes: int) -> None:
_transfer_avatar_to_s3(user)
else: # nocoverage
connection.close()
cache._cache.disconnect_all()
_cache = getattr(cache, "_cache")
assert isinstance(_cache, bmemcached.Client)
_cache.disconnect_all()
with multiprocessing.Pool(processes) as p:
for out in p.imap_unordered(_transfer_avatar_to_s3, users):
pass
@@ -71,7 +74,9 @@ def transfer_message_files_to_s3(processes: int) -> None:
_transfer_message_files_to_s3(attachment)
else: # nocoverage
connection.close()
cache._cache.disconnect_all()
_cache = getattr(cache, "_cache")
assert isinstance(_cache, bmemcached.Client)
_cache.disconnect_all()
with multiprocessing.Pool(processes) as p:
for out in p.imap_unordered(_transfer_message_files_to_s3, attachments):
pass
@@ -101,7 +106,9 @@ def transfer_emoji_to_s3(processes: int) -> None:
_transfer_emoji_to_s3(realm_emoji)
else: # nocoverage
connection.close()
cache._cache.disconnect_all()
_cache = getattr(cache, "_cache")
assert isinstance(_cache, bmemcached.Client)
_cache.disconnect_all()
with multiprocessing.Pool(processes) as p:
for out in p.imap_unordered(_transfer_emoji_to_s3, realm_emojis):
pass