-
-
Notifications
You must be signed in to change notification settings - Fork 398
cli: use cached index with lib search (#1624) #1789
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
Conversation
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.
Thanks for the PR.
I see that you have taken the same patch for the core search
and that's great!
I've made some comments to simplify this patch, IMHO after we validate these changes we can "backport" some of the suggestions to the core search
command too.
Finally, the integration tests are failing, some of the tests expect the Upgrading library_index...
message from the CLI, but this is no more happening after the patch. Could you fix the tests too? https://github.com/arduino/arduino-cli/runs/7155610048?check_suite_focus=true#step:10:6806
// The behavior of now.After(T) is confusing if T < 0 and MTIME in the future, | ||
// and is probably not what the user intended. Disallow negative T and inform | ||
// the user that positive thresholds are expected. | ||
if modTimeThreshold < 0 { | ||
feedback.Error(tr("Timeout must be non-negative: %dns (%s)", modTimeThreshold, duration)) | ||
os.Exit(errorcodes.ErrBadArgument) | ||
} |
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 would not bother too much with validating the timeout since it's a hardcoded constant.
// The behavior of now.After(T) is confusing if T < 0 and MTIME in the future, | |
// and is probably not what the user intended. Disallow negative T and inform | |
// the user that positive thresholds are expected. | |
if modTimeThreshold < 0 { | |
feedback.Error(tr("Timeout must be non-negative: %dns (%s)", modTimeThreshold, duration)) | |
os.Exit(errorcodes.ErrBadArgument) | |
} |
// Valid duration units are "ns", "us" (or "µs"), "ms", "s", "m", "h". | ||
// Use a duration of 0 to always update the index. | ||
func indexNeedsUpdating(duration string) bool { |
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'd like to change the indexUpdateInterval
constant to a time.Duration
like:
const indexUpdateInterval = 60 * time.Minute
so the indexNeedsUpdating
function may take directly a time.Duration
// Valid duration units are "ns", "us" (or "µs"), "ms", "s", "m", "h". | |
// Use a duration of 0 to always update the index. | |
func indexNeedsUpdating(duration string) bool { | |
func indexNeedsUpdating(timeout time.Duration) bool { |
feedback.Error(tr("Timeout must be non-negative: %dns (%s)", modTimeThreshold, duration)) | ||
os.Exit(errorcodes.ErrBadArgument) | ||
} | ||
return modTimeThreshold == 0 || now.After(info.ModTime().Add(modTimeThreshold)) |
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.
Also this one can be much more simplified, something like
return time.Since(info.ModTime()) > timeout
should work.
I think that just removing these two lines Lines 456 to 457 in f556aff
|
Please check if the PR fulfills these requirements
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)Feature
A new copy of
library_index.json
is downloaded every timelib search
is called (unconditionally).A new copy of
library_index.json
is downloaded every timelib search
is called and either one of the following conditions exists:titled accordingly?
No
lib search
#1624See how to contribute