Update replace-placeholder.sh
Speed up the replacement loop
- only look at files with the "$FROM" pattern
A quick test with v4.5.3 shows these results:
Current:
root@4f3f81c57237:/calcom/apps# FROM='http://localhost:3000'; TO='https://cal.example.com'; time find web/.next/ web/public/ -type f | while read file; do sed -i "s|$FROM|$TO|g" "$file"; done
real 1m22.762s
user 0m52.981s
sys 0m44.544s
New:
root@a6f1f3600029:/calcom/apps# FROM='http://localhost:3000'; TO='https://cal.example.com'; time for file in $(egrep -r -l "$FROM" web/.next/ web/public/); do sed -i -e "s|$FROM|$TO|g" "$file"; done
real 0m3.356s
user 0m1.487s
sys 0m1.958s
Optimization generally LGTM, but without knowing this project well enough, I'd be worried how you got to so many files in these directories that a simple looped sed ends up needing 1m22 to process.
@dvusboy Did you observe these times on custom builds only? Did you maybe have some kind of leftovers from older builds locally that got copied into the final image?
Well, 2 points:
- To get the timing difference, I just run the script in-place, changed and not changed. It's pretty easy to do by overriding
CMDto the Docker image with/bin/bashwithdocker run. - It is pretty obvious that the changes would speed things up by reducing the number of files needing changes. The extent was a little surprising.
I didn't change much to the sed line, just explicitly prefixing the script with -e.
Ah ok, so you ran it outside of the Docker build? That would explain the huge amount of time needed initially (I assume a local build ends up having much more/larger files then a Docker build).
As said, the optimisation itself is a LGTM.