Skip to content

perf: no caching for prefer timezone - #5128

Merged
steve-chavez merged 4 commits into
PostgREST:mainfrom
steve-chavez:fix-timezone
Aug 4, 2026
Merged

perf: no caching for prefer timezone #5128
steve-chavez merged 4 commits into
PostgREST:mainfrom
steve-chavez:fix-timezone

Conversation

@steve-chavez

@steve-chavez steve-chavez commented Jul 25, 2026

Copy link
Copy Markdown
Member

Fixes #5100 and #4751.

This essentially removes the timezones from the schema cache. Please read the latest comments on #5100 to fully understand the implementation.

To discuss

Edit: We'll keep the revert as we're not going to have a lenient variant as discussed below.

Here I've also removed the db-timezone-enabled config by reverting d6c338d. But we might want to keep it given that the query in the handling=lenient case is kinda expensive (ref). Some users might not want clients forcing that query.

Or perhaps we can have a config similar to the one for Prefer:tx, only allowing the strict timezone handling.

Comment thread test/spec/Feature/Query/Preferences/TimezoneSpec.hs Outdated
@steve-chavez
steve-chavez force-pushed the fix-timezone branch 2 times, most recently from ad07b57 to 8351d26 Compare July 25, 2026 05:00
@steve-chavez
steve-chavez marked this pull request as ready for review July 25, 2026 05:01
@wolfgangwalther

Copy link
Copy Markdown
Member

This is not a fix, but a performance improvement.

@taimoorzaeem

Copy link
Copy Markdown
Member

Oh, I think you missed removing the changelog entry from the unreleased section:

- Add config `db-timezone-enabled` for optional querying of timezones by @taimoorzaeem in #4751

@steve-chavez

Copy link
Copy Markdown
Member Author

This is not a fix, but a performance improvement.

Ah but the incorrect reloading part we discussed on #4751 (comment) seems like a bug to me. If someone did modify their timezones the cache would not be reloaded. For #5100 it would be purely perf but I dunno which one wins here.

@wolfgangwalther

Copy link
Copy Markdown
Member

incorrect reloading part we discussed on #4751 (comment) seems like a bug to me. If someone did modify their timezones the cache would not be reloaded.

"automatic reloading" is not a feature that PostgREST provides. It's part of the documentation for how to set it up. The bug is not in PostgREST - it's just that this recommendation does not cover this aspect. You could argue that this recommendation is wrong - but we never call wrong things in the docs "bugs" or changes to the docs "fix".

One approach to resolve this issue would be to correct the docs as I mentioned earlier. You instead opted to change the code as part of a performance improvement, which makes the issue obsolete. Still not a bug, nor a fix. Especially the PR title / commit message is just wrong: The caching of timezones was always correct, there was not a problem with it.

Comment thread src/library/PostgREST/Query/SqlFragment.hs Outdated
This was referenced Jul 26, 2026
@steve-chavez steve-chavez added the breaking change A bug fix or enhancement that would cause a breaking change label Jul 27, 2026
@steve-chavez steve-chavez self-assigned this Jul 27, 2026
@steve-chavez steve-chavez added this to the v16 milestone Jul 27, 2026
@steve-chavez
steve-chavez force-pushed the fix-timezone branch 2 times, most recently from 8f4a8df to 8c79c57 Compare July 31, 2026 03:23
@steve-chavez steve-chavez changed the title fix: incorrect caching of timezones perf: no caching for prefer timezone Jul 31, 2026
@steve-chavez

Copy link
Copy Markdown
Member Author

Changed the commit prefix to perf. Also added tests and docs for the numeric offset timezones on separate commits. Offsets are a new feature but I didn't knew how to separate them from the perf commit.

@steve-chavez
steve-chavez force-pushed the fix-timezone branch 2 times, most recently from 6907417 to f6c539c Compare July 31, 2026 03:38
@taimoorzaeem

Copy link
Copy Markdown
Member

Just did a rg -n "dbTimezone" in project root, looks like we forgot to remove this:

"dbTimezones": ["..."]

and this:

"dbTimezones",
],
)
def test_schema_cache_snapshot(baseenv, key, snapshot_yaml):
"Dump of schema cache should match snapshot."
schema_cache = yaml.load(cli(["--dump-schema"], env=baseenv), Loader=yaml.Loader)
formatted = yaml.dump(
schema_cache[key],
encoding="utf8",
allow_unicode=True,
Dumper=yaml.SafeDumper if key == "dbTimezones" else ExtraNewLinesDumper,

@steve-chavez
steve-chavez force-pushed the fix-timezone branch 6 times, most recently from 2bc7c2b to 70247cc Compare July 31, 2026 18:01

@taimoorzaeem taimoorzaeem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment thread src/library/PostgREST/Response.hs Outdated
Comment thread CHANGELOG.md

@wolfgangwalther wolfgangwalther left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase to resolve conflicts, too.

Comment thread docs/references/api/preferences.rst
Comment thread docs/references/api/preferences.rst Outdated
Comment thread docs/references/api/preferences.rst Outdated
Comment thread src/library/PostgREST/Query/PreQuery.hs Outdated
Comment thread test/io/test_io.py
@steve-chavez
steve-chavez force-pushed the fix-timezone branch 2 times, most recently from 6ee378b to d96dadd Compare August 4, 2026 05:27
@steve-chavez

Copy link
Copy Markdown
Member Author

Addressed all the feedback.

`Prefer: timezone` no longer requires the schema cache.
Previously this required caching `pg_timezone_names` which was slow in some systems.

Closes PostgREST#5100 and
PostgREST#4751.
@steve-chavez
steve-chavez merged commit e441784 into PostgREST:main Aug 4, 2026
28 of 29 checks passed
@wolfgangwalther

Copy link
Copy Markdown
Member

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change A bug fix or enhancement that would cause a breaking change

Development

Successfully merging this pull request may close these issues.

SELECT name FROM pg_timezone_names; has variable performance, affecting startup time

4 participants