Skip to content

Commit

Permalink
refactor(ThreadsAPI): Avoid instantiating a new Redis instance each t…
Browse files Browse the repository at this point in the history
…ime it's needed
  • Loading branch information
elisa-a-v committed Nov 13, 2024
1 parent 8c785fe commit 25d5f23
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bc/channel/utils/connectors/threads_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

_BASE_API_URL = "https://graph.threads.net/v1.0"

r = make_redis_interface("CACHE")


class ThreadsAPI:
"""
Expand Down Expand Up @@ -178,7 +180,6 @@ def validate_access_token(self) -> tuple[bool, str]:
tuple[bool, str]: A tuple where the first element is a boolean
indicating whether the token was refreshed, and the second element is the current access token.
"""
r = make_redis_interface("CACHE")
refreshed = False

try:
Expand Down Expand Up @@ -258,7 +259,6 @@ def _set_token_expiration_in_cache(self, expires_in: int):
"""
delay = timedelta(seconds=expires_in)
expiration_date = (datetime.now(timezone.utc) + delay).isoformat()
r = make_redis_interface("CACHE")
key = self._get_expiration_key()
try:
r.set(
Expand Down

0 comments on commit 25d5f23

Please sign in to comment.