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

Allow wildcards in CACHALOT_UNCACHABLE_TABLES #186

Open
jacobjove opened this issue May 24, 2021 · 4 comments · Fixed by #187
Open

Allow wildcards in CACHALOT_UNCACHABLE_TABLES #186

jacobjove opened this issue May 24, 2021 · 4 comments · Fixed by #187

Comments

@jacobjove
Copy link

Description

It would be nice to be able to use wildcards (*) in the CACHALOT_UNCACHABLE_TABLES setting; e.g.,

CACHALOT_UNCACHABLE_TABLES = frozenset(
    (
        'django_migrations',
        'myapp_*',
    )

Rationale

In the case that all models in a particular app must be excluded from Cachalot, this is very convenient.

Alternatives?

//: # Add another setting like CACHALOT_UNCACHABLE_APPS

@Andrew-Chen-Wang
Copy link
Collaborator

Andrew-Chen-Wang commented May 24, 2021

Thanks for the suggestion @iacobfred ! I like the alternative better as that makes sure we keep performance on par. I believe I can get all models associated with an app on initial Django setup and add that to CACHALOT_UNCACHABLE_TABLES, but that means cachalot must be placed after all others apps, right? If anything, I love the CACHALOT_UNCACHABLE_APPS idea. (Note to self: probably adding CACHALOT_CACHABLE_APPS is logical).

My initial analysis of the original suggestion

My only concern would be performance / implementation of this wildcard. I've identified the most prominent areas in which it's used:

def is_cachable(table):
whitelist = cachalot_settings.CACHALOT_ONLY_CACHABLE_TABLES
if whitelist and table not in whitelist:
return False
return table not in cachalot_settings.CACHALOT_UNCACHABLE_TABLES
def are_all_cachable(tables):
whitelist = cachalot_settings.CACHALOT_ONLY_CACHABLE_TABLES
if whitelist and not tables.issubset(whitelist):
return False
return tables.isdisjoint(cachalot_settings.CACHALOT_UNCACHABLE_TABLES)
def filter_cachable(tables):
whitelist = cachalot_settings.CACHALOT_ONLY_CACHABLE_TABLES
tables = tables.difference(cachalot_settings.CACHALOT_UNCACHABLE_TABLES)
if whitelist:
return tables.intersection(whitelist)
return tables

We use sets a lot, and a wildcard would add a severe amount of Python rather than the C impl and when you think about ORMs (and from internals, these methods are called a lot), this adds a huge overhead.

@Andrew-Chen-Wang
Copy link
Collaborator

@iacobfred please let me know if #187 fixes this!

@jacobjove
Copy link
Author

@iacobfred please let me know if #187 fixes this!

@Andrew-Chen-Wang, yes it does! Thanks!

@Andrew-Chen-Wang
Copy link
Collaborator

Andrew-Chen-Wang commented May 27, 2021

I'm still going to see if I can implement this in the quest to deploy Django with partitioned tables... ref #153 (btw I won't comment on here anymore to not annoy with notifications, but leaving it open for reference later on).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants