Remove import-time string processing from cache backend and models#1169
Conversation
Co-authored-by: adamchainz <857609+adamchainz@users.noreply.github.com>
|
@copilot do the same for the |
Co-authored-by: adamchainz <857609+adamchainz@users.noreply.github.com>
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 <857609+adamchainz@users.noreply.github.com>
... 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.