-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
MM-57839: Rewrite static assets only if needed #27076
base: master
Are you sure you want to change the base?
Conversation
Refactor UpdateAssetsSubpathInDir so that the actual rewriting of files happen in two different functions: one for root.html, another for manifest.json and *.css files. I would have wanted to simply do a if pathToReplace == newPath { return nil } when those two variables are defined, but the logic for root.html is not that simple, and that may miss some edge cases, so I opted out for simply moving the actual rewriting to individual functions, which check for their corresponding conditions to perform the update: 1. for root.html, check that the edited file is indeed different than the original one 2. for manifest.json and *.css files, rewrite them only if pathToReplace != newPath, which in this case is clear that that's the only modification we do
@hmhealey, adding you here in case you're familiar with this client static assets rewriting. |
Swapping me for Jesse, who should have more context on this area. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -110,13 +124,29 @@ func UpdateAssetsSubpathInDir(subpath, directory string) error { | |||
newRootHTML = strings.Replace(newRootHTML, "</style>", fmt.Sprintf("</style><script>%s</script>", script), 1) | |||
} | |||
|
|||
if newRootHTML == oldRootHTML { | |||
mlog.Debug("No need to rewrite unmodified root.html", mlog.String("from_subpath", pathToReplace), mlog.String("to_subpath", newPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to just log nothing in this case? (Unix philosophy and all?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know that was part of the Unix philosophy 👀 But given this is a debug-level log, I'm in favour of keeping it. I don't think there's such thing as a lot of debug logging! If you have a stronger opinion, I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only 0/5, but if we DEBUG logged everything that /didn't/ happen, I would wager that would be a /lot/ of debug logging ;P. My hope whenever scrubbing logs is to look for positive evidence of something, and in that context, fewer logs that speak to something that actually happened are strictly more helpful. But this is a one-off, so I'm really only -1/5 :D
E2E test triggered successfully for PR #27076. The corresponding commit's status check will be available shortly. |
E2E test run is starting for commit
|
@DHaussermann, this PR modifies the code that updates the static assets served by MM when changing the subpath where the application is served. Could you run a smoke test to ensure that everything is working as expected? If something is broken, it should be quite obvious, as in nothing works. We should ideally test that changing the subpath also works, but I don't know how easy that is (if it's even possible) in a cloud test server. |
Summary
Refactor
UpdateAssetsSubpathInDir
so that the actual rewriting of files happen in two different functions: one forroot.html
, another formanifest.json
and*.css
files.I would have wanted to simply do an
if pathToReplace == newPath { return nil }
when those two are defined, but the logic forroot.html
is not that simple*, and that may miss some edge cases, so I opted out for simply moving the actual rewriting to individual functions, which check for their corresponding conditions to perform the update:root.html
, check that the edited file is indeed different than the original onemanifest.json
and*.css
files, rewrite them only ifpathToReplace != newPath
, which in this case is clear that that's the only modification we do.The logic is exactly the same as before except for skipping the rewrite when those conditions are not met.
*I don't really understand this block:
When can that be rewritten if not here?
Ticket Link
https://mattermost.atlassian.net/browse/MM-57839
Screenshots
--
Release Note
Fix #26769