-
Notifications
You must be signed in to change notification settings - Fork 595
Rewite caching in local::unix module
#1457
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
base: main
Are you sure you want to change the base?
Conversation
672b038 to
16b7be7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1457 +/- ##
==========================================
- Coverage 91.82% 91.41% -0.42%
==========================================
Files 40 40
Lines 18345 18382 +37
==========================================
- Hits 16846 16804 -42
- Misses 1499 1578 +79 ☔ View full report in Codecov by Sentry. |
That makes it very tricky to review. Pretty sure there are ways to break it down into smaller pieces. |
Yes, I realize that 😞. Maybe I can split it in:
And maybe that can be divided in more than two commits, hard to say. Does that sound better reviewable? |
16b7be7 to
e71f66f
Compare
|
I'll see what I can do to split it up more. |
|
Setting to draft for now. This is only tangentially related to the work of converting the API to |
d5a7efb to
68553d5
Compare
6508743 to
e6b5574
Compare
e6b5574 to
b485ac2
Compare
Existing code
At a high level, the
unixmodule tries to find the current time zone, load the data for it and cache the result.TZenvironment variable has changed or if the modification time of the/etc/localtimesymlink has changed.tz_info::timezone::TimeZone::local. If theTZvariable is set it can load TZ data from the following sources:ZONE_INFO_DIRECTORIES/etc/localtimesymlinkTZvariable is an errorTZvariable is not set it uses the/etc/localtimesymlink.unix::current_zonethen specifiesunix::fallbackas a third fallback.This gets the time zone name using the
iana_time_zonecrate, and tries to load it fromTZDB_LOCATION(which is currently not the same asZONE_INFO_DIRECTORIES).Problems with this setup are that the logic lives in different places, that the caching code does not detect changes except the most limited form, and that the logic to look up the
zoneinfodirectory is implemented in two different ways.New code
Everything related to loading the time zone data is implemented as methods on a
CachedTzInfotype.Caching and updating happens with the methods:
CachedTzInfo::tz_info()refresh_cache()needs_update()tz_env_var_changed()symlink_changed()tz_name_changed()read_tz_info()read_from_tz_env()read_from_symlink()read_with_tz_name()tzdb_dir()I kept methods such as
read_with_tz_name()andtz_name_changed()close together so it is easier to see they work similar.The
CachedTzInfotype remembers the last source that was succesfull, and stores all information needed to check the cache is up to date:TZvariable, time zone name, path, andzoneinfodirectory.New functionality is that we cache the directory with the time zone database, and respect the
TZDIRenvironment variable (fixes #1265).All potential error sources are returned with a
Result</* */, ()>type.This is a rewrite, I can't pretend it to be a refactor.