refactor: check if the remote exists just before reading it
Hey!
Context
When we have multiple remote Taskfiles, I noticed it can takes time to download all of them, so I added --offline.
But it was still taking times (either in running tasks, either in the autocomplete) so I took a look.
Problem
It appears that we check if the file exist in the remote even if the Offline flags is set, this cause unnecessary HTTP requests (at the end it takes more time than needed)
Solution
Move this check in Read method, this way it'll run only if there is no --offline .
I don't know if store the logger in the struct can causes performance issues, I did not notice that.
NOTE: as Read is executed before ResolveEntrypoint it shoud not cause any issues. I have a remote Taskfile included in a remote one and it's working
It can also improve preformance for this issue https://github.com/go-task/task/issues/1406
Benchmark locally
I've ran some local benchmark in my projects :
vs
EDIT:
Thanks to @ccoVeille, it appears that the timeout error does not work on main. cf :
with the fix :
PS: we may need to discuss about putting --offline by default in the autocomplete files or at least provide an env variable to do it easily
PS2: if this PR is merged, will backport to my remote-git PR
Ok third attempt I think I have to desired behavior:
- If the request timeout && --download : error
- If the request timeout, use cached copy :
- If the cache is here = OK
- If not = error
- if the request does not timeout = OK @pd93 Let me know if I missed something in the behavior