[feature] Run collectstatic only when python dependencies change #246#473
Conversation
Implementation of smart collectstatic logic to compare freeze hash before calling collectstatic, saving time and avoiding redundant calls. Fixes openwisp#246
Added error handling in the collectstatic logic and usage of relative path instead of absolute in init_command.sh. Fixes openwisp#246
nemesifier
left a comment
There was a problem hiding this comment.
@stktyagi great progress here!
Can you please add an env var called COLLECTSTATIC_WHEN_DEPS_CHANGE, defaulting to True, which allows us to disable this feature?
This can be useful during development or on systems where we are using the
development version and the version identifier of the openwisp modules does not change but we still need to call collectstatic anyway.
We'll need to add this var to the docs as well.
…penwisp#246 Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it. Fixes openwisp#246
…penwisp#246 Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it. Fixes openwisp#246
…penwisp#246 Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it. Fixes openwisp#246
|
There was some conflict between formatter and the qa tester while adding the docstring in collecstatic, hence the redundant commits. Will make sure in the future. |
|
|
||
| def main(): | ||
| if os.environ.get("COLLECTSTATIC_WHEN_DEPS_CHANGE", "true").lower() == "false": | ||
| print("COLLECTSTATIC_WHEN_DEPS_CHANGE is false; skipping collectstatic.") |
There was a problem hiding this comment.
This is not what I meant.
If the env var is False we shall always execute collectstatic. Not executing it is not an option.
There was a problem hiding this comment.
Oh, sorry for the misunderstanding. In fact I was wondering the previous change.
For updation :-
if unset -> default to true -> run if "pip freeze" changed
if false -> always execute collectstatic
Post commit, if the env var is true we run collectstatic if pip freeze changes else we run collectstatic each time. Fix openwisp#473
nemesifier
left a comment
There was a problem hiding this comment.
I did some minor improvements, feel free to review. LGTM ✔️
looks like I forgot to update the docs, my bad. Thank you for doing that. |
Checklist
Reference to Existing Issue
Closes #246
Description of Changes
Added a collectsatic_control.py file that computes a hash of the current installed Python packages (pip freeze output) and connects to Redis to retrieve a previously stored hash. If the hash is missing or changed, it runs Django’s collectstatic command to gather static files and updates the stored hash in Redis and if the hash is unchanged, it skips running collectstatic.