-
-
Notifications
You must be signed in to change notification settings - Fork 172
Use source mtime for Last-Modified and unify modified-since semantics#1326
Use source mtime for Last-Modified and unify modified-since semantics #1326lovasoa wants to merge 1 commit into
Conversation
lovasoa
commented
Jun 12, 2026
@codex I clearly see the runtime overhead, but not the concrete benefits. We are making one entire new db query per file, for no functional change ? Either justify it or drop it
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac22aeeb36
i️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
P2 Badge Handle nullable database modification timestamps
The documented and generated sqlpage_files schemas allow last_modified to be NULL for several databases, so a row inserted with an explicit NULL was previously still readable and servable. Decoding it as DateTime<Utc> rejects NULL, and serve_file now calls this method before every static-file read, causing requests for such DB-backed assets to return a 500 instead of their contents. Decode an optional timestamp and provide an appropriate fallback or omit the header for NULL values.
Useful? React with 👍 / 👎.
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.
@codex fix
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.
You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.
Summary
- Dropped the source-mtime/
Last-Modifiedchanges and restored the prior static-file serving behavior, so ordinary database-backed file responses no longer perform an additional metadata query before reading the file. Conditional requests still perform only the existing modified-since check. src/webserver/http.rsL438-L470 - Retained the concrete correctness fix: database-backed files are now considered modified only when
last_modifiedis strictly greater than the supplied timestamp. src/filesystem.rsL301-L312 - Added regression coverage confirming that a database-backed file is not considered modified since its exact modification timestamp. src/filesystem.rsL478-L492
- Committed the changes with commit
85eec98(Avoid extra query for static file metadata) and created the follow-up PR "Avoid extra query for static file metadata."
Testing
- ✅
cargo fmt --all - ✅
cargo fmt --all -- --check - ✅
git diff --check ⚠️ cargo test— blocked by the environment becauselibsqlite3-sys 0.38.1uses the unstable Rustcfg_selectfeature.⚠️ cargo clippy --all-targets --all-features -- -D warnings— blocked by the samelibsqlite3-sys 0.38.1build error.
lovasoa
commented
Jun 12, 2026
@codex monitor ci
error[E0283]: type annotations needed
--> src/webserver/http.rs:448:54
|
448 | let last_modified = HttpDate::from(last_modified.into());
| -------- ^^^^
| |
| type must be known at this point
|
= note: multiple impls satisfying actix_web::http::header::HttpDate: std::convert::From<_> found in the following crates: actix_http, core:
- impl std::convert::Fromstd::time::SystemTime for actix_web::http::header::HttpDate;
- impl std::convert::From for T;
help: try using a fully qualified path to specify the expected types
|
448 - let last_modified = HttpDate::from(last_modified.into());
448 + let last_modified = HttpDate::from(<chrono::DateTimechrono::Utc as std::convert::Into>::into(last_modified));
|
error[E0283]: type annotations needed
--> src/webserver/http.rs:448:54
|
448 | let last_modified = HttpDate::from(last_modified.into());
| ^^^^
|
= note: multiple impls satisfying _: std::convert::From<chrono::DateTime<chrono::Utc>> found in the chrono crate:
- impl std::convert::From<chrono::DateTimechrono::Utc> for chrono::DateTimechrono::FixedOffset;
- impl std::convert::From<chrono::DateTimechrono::Utc> for chrono::DateTimechrono::Local;
= note: required for chrono::DateTime<chrono::Utc> to implement std::convert::Into<_>
help: try using a fully qualified path to specify the expected types
|
448 - let last_modified = HttpDate::from(last_modified.into());
448 + let last_modified = HttpDate::from(<chrono::DateTimechrono::Utc as std::convert::Into>::into(last_modified));
|
For more information about this error, try rustc --explain E0283.
error: could not compile sqlpage (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile sqlpage (lib test) due to 2 previous errors
Error: Process completed with exit code 101.
You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.
Motivation
Last-Modified: now, which changes on every request and prevents meaningful cache revalidation.>vs DB>=), causing inconsistent conditional-request behavior.Description
FileSystem::last_modifiedwhich returns the real modification time from the local filesystem or thelast_modifiedcolumn in the DB-backedsqlpage_filestable.last_modifiedvalue (make_last_modified_queryandlast_modified_in_db) and changed the DBwas_modifiedcheck to strict>to match local semantics.serve_fileto computelast_modified, use it forIf-Modified-Sincevalidation, and insert the sameLast-Modifiedvalue on both200 OKand304 Not Modifiedresponses.Last-Modifiedand revalidate correctly, and an assertion in the DB test that a file is not considered modified since its exact timestamp.Testing
cargo fmt --allandcargo fmt --all -- --check, and verifiedgit diff --check; these passed.cargo clippy --all-targets --all-features -- -D warnings, but it was blocked by the environmentlibsqlite3-sys 0.38.1build error using the unstablecfg_selectfeature with the installedrustc.cargo testand running the newstatic_file_uses_source_last_modified_for_revalidationtest, but test execution was blocked by the samelibsqlite3-sysbuild error.libsqlite3-sys(or the dependency is adjusted).Codex Task