-
Notifications
You must be signed in to change notification settings - Fork 0
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
added is_cachable to requirements #608
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,20 @@ def check_user_constraints(self, raise_exception=True): | |
is_verified = constraint.is_observed( | ||
**cdata, from_time=int(self.raffle.start_at.timestamp()), context={"request": self.request} | ||
) | ||
caching_time = 60 * 60 if is_verified else 60 | ||
expiration_time = time.time() + caching_time | ||
cache_data = { | ||
"is_verified": is_verified, | ||
"info": info, | ||
"expiration_time": expiration_time, | ||
} | ||
cache.set( | ||
cache_key, | ||
cache_data, | ||
caching_time, | ||
) | ||
if constraint.is_cachable: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider refactoring the caching logic into a separate function. The new code introduces additional complexity due to the conditional caching logic based on def cache_constraint_result(cache_key, is_verified, info):
caching_time = 60 * 60 if is_verified else 60
expiration_time = time.time() + caching_time
cache_data = {
"is_verified": is_verified,
"info": info,
"expiration_time": expiration_time,
}
cache.set(cache_key, cache_data, caching_time)
return cache_data
# In the main function
if constraint.is_cachable:
cache_data = cache_constraint_result(cache_key, is_verified, info)
else:
cache_data = {"is_verified": is_verified, "info": info}
if not cache_data.get("is_verified"):
error_messages[c.title] = constraint.response
result[c.pk] = cache_data This refactoring should help in making the code cleaner and easier to maintain. |
||
caching_time = 60 * 60 if is_verified else 60 | ||
expiration_time = time.time() + caching_time | ||
cache_data = { | ||
"is_verified": is_verified, | ||
"info": info, | ||
"expiration_time": expiration_time, | ||
} | ||
cache.set( | ||
cache_key, | ||
cache_data, | ||
caching_time, | ||
) | ||
|
||
if not cache_data.get("is_verified"): | ||
error_messages[c.title] = constraint.response | ||
result[c.pk] = cache_data | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider adding a comment explaining the purpose and usage of the
is_cachable
attributeThis attribute controls whether the constraint verification result should be cached. It might be helpful to provide examples of when it should be set to False, such as for time-sensitive or security-critical verifications.