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

feat: cache queries in filters #124

Merged
merged 9 commits into from
Mar 8, 2023
Merged

Conversation

dshafer
Copy link
Collaborator

@dshafer dshafer commented Mar 4, 2023

  • [] Update CHANGELOG.md
  • Update README.md (as needed)
  • New dependencies were added to pyproject.toml
  • pip install succeeds with a clean virtualenv
  • There are new or modified tests that cover changes
  • Test coverage is maintained or expanded

expand_children=None,
klass=None,
filter_cache=None,
debug_indent="",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is separator rather than indent. Have I misunderstood the intent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an indent, it just helps to make the logs easier to match up with what level of the response object the filters are working on. We can probably take the debug logging out now that the filters are working.

filter_def,
expand_children=expand_dict,
klass=inst.__class__,
filter_cache={},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How concerned should we be about the size of this object that we're passing? It could be massive, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worthwhile doing something like this to track?

cache_obj = {}
filtered_val = _apply_filters_to_object(..., filter_cache=cache_obj, ...)
logger.info(... cache_obj.__sizeof__()...)
return filtered_val

Copy link
Collaborator Author

@dshafer dshafer Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smholloway it's pass-by-reference, so no concern about size when passing it in function calls. I don't even really think we need to track it; the total filter_cache object is going to be comparable in size to the overall response dict that we're returning anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Makes sense to me 👍

expand_children=None,
klass=None,
filter_cache=None,
debug_indent="",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is debug-specific code. A slight shift tracking depth would put a spin on it (then the prefix could just be " " * depth.

@smholloway
Copy link
Collaborator

I have no problems with this change and would approve. I defer to Demian for a more thorough review.

Copy link
Member

@demianbrecht demianbrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see the logging updated to depend on config rather than env vars. Other than that, LGTM 👍

):
debug_indent += " "
is_cacheable = False
debug_log = getattr(settings, "DDA_FILTER_CACHE_DEBUG_LOG", False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use an environment variable rather than rely on built-in log configuration? Instead of logger.info this could use logger.debug and then this module's log level could be set through config.

expand_this,
expand_children,
filter_cache,
indent,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't used anymore, is it? Should it be removed?

@@ -107,22 +146,60 @@ def _get_filtered_field_value(
return None


def _make_filter_cache_key(expand_children, klass, pk):
return (str(expand_children), klass, str(pk))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

klass would end up being the string repr of the instance's class, right? Would f"{klass.__module__}.{klass.__name__}" be slightly preferable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

klass is the actual type object, not a str.

expand_children has to be stringified because dicts are not hashable. pk has to be stringified because otherwise we get a mix of uuid and str that don't match like they should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'm dumb. I was thinking it was being serialized for some reason.

demianbrecht
demianbrecht previously approved these changes Mar 8, 2023
@dshafer dshafer merged commit 4e36059 into main Mar 8, 2023
@dshafer dshafer deleted the feature/cache-queries-in-filters branch March 8, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants