Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the lookup pepper in the HashingMetadataStore. #475

Merged
merged 3 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/475.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cache the lookup pepper in the `HashingMetadataStore`.
7 changes: 7 additions & 0 deletions sydent/db/hashing_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@
class HashingMetadataStore:
def __init__(self, sydent: "Sydent") -> None:
self.sydent = sydent
self._cached_lookup_pepper: Optional[str] = None

def get_lookup_pepper(self) -> Optional[str]:
"""Return the value of the current lookup pepper from the db

:return: A pepper if it exists in the database, or None if one does
not exist
"""

if self._cached_lookup_pepper is not None:
return self._cached_lookup_pepper

cur = self.sydent.db.cursor()
res = cur.execute("select lookup_pepper from hashing_metadata")
# Annotation safety: lookup_pepper is marked as varchar(256) in the
Expand All @@ -52,6 +57,8 @@ def get_lookup_pepper(self) -> Optional[str]:
if isinstance(pepper, bytes):
pepper = pepper.decode("UTF-8")

self._cached_lookup_pepper = pepper

return pepper

def store_lookup_pepper(
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
Expand Down