-
-
Notifications
You must be signed in to change notification settings - Fork 115
Remove import-time string processing from cache backend and models #1169
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
Conversation
Co-authored-by: adamchainz <[email protected]>
|
@copilot do the same for the |
Co-authored-by: adamchainz <[email protected]>
Done! I've replaced all Changes made in commit 2af3a00:
The SQL strings are functionally equivalent (verified by normalizing and comparing). All linting checks pass. Net reduction: 126 lines of code. |
|
@copilot rather than smoosh everything together into one string, preserve the original indentation, even if it needs something like: # fmt: off
x = (
"f("
"x"
")"
)
# fmt: on |
Co-authored-by: adamchainz <[email protected]>
... Done! I've updated all SQL strings to preserve the original indentation using Changes in commit c9c88fd:
The SQL strings now look like this: # fmt: off
_add_query = (
"INSERT INTO {table} (cache_key, value, value_type, expires) "
"VALUES (%s, %s, %s, %s) "
"ON DUPLICATE KEY UPDATE "
"value=IF(expires > @tmp_now:=%s, value, VALUES(value)), "
"value_type=IF(expires > @tmp_now, value_type, VALUES(value_type)), "
"expires=IF("
"expires > @tmp_now, "
"IFNULL("
"LEAST(LAST_INSERT_ID(444), NULL), "
"expires"
"), "
"VALUES(expires)"
")"
)
# fmt: on |
The cache backend and models were calling
textwrap.dedent()andcollapse_spaces()at import time to format SQL strings and expressions, adding unnecessary overhead to module loading.Changes
textwrap.dedentimport and call from cache.pycollapse_spaces()function from utils.pycollapse_spaces()calls (18 total) with plain strings across:dedent()call oncreate_table_sqlwith parenthesized string literal containing explicit newlines# fmt: offand# fmt: oncomments to preserve original indentation structure for readabilityBefore:
After:
Impact
.format()and.splitlines()usage in tests and management commandsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.