Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

Implementation Plan for If-Modified-Since Caching

  • Understand the current file download implementation
  • Query database for modification timestamps (created_at for attachments, timestamp_received for email bodies)
  • Add Last-Modified header to file responses
  • Implement If-Modified-Since request header handling
  • Return 304 Not Modified when appropriate
  • Add Cache-Control headers for better browser caching
  • Add tests for the caching functionality
  • Validate changes work correctly (syntax check, logic verification, code review, security scan)
  • Address PR feedback:
    • Use queryOneOrNone() for reliable null handling
    • Move caching headers after successful extraction to avoid errors inheriting them
    • Fix $att->attachment_id to $att->id
    • Add immutable directive to attachment Cache-Control
    • Add e2e test for attachment caching with 304 behavior
    • Use queryOneOrNone() consistently in both timestamp methods
    • Refactor duplicate attachment mapping code into helper method

Summary

Successfully implemented HTTP caching for file downloads using If-Modified-Since/Last-Modified headers and addressed all PR feedback. The implementation:

Minimal changes: Surgical modifications with no breaking changes
Backward compatible: Existing methods unchanged, new methods added
Standards compliant: Uses RFC 7231/7232 HTTP caching headers with immutable directive
Well tested: Automated tests for both email body and attachment caching including 304 behavior
Secure: Uses private caching, maintains authentication/authorization
Efficient: 1 hour cache for email bodies, 1 year immutable cache for attachments
Robust: Proper error handling with queryOneOrNone(), headers set after successful processing
Clean code: Eliminated duplication with helper method for attachment mapping

Benefits:

  • Reduces bandwidth usage by avoiding re-downloads of unchanged files
  • Faster page loads through browser caching
  • Reduced server load
  • Better user experience
Original prompt

This section details on the original issue you should resolve

<issue_title>For file download, implement If-Modified-Since and similar caching for browsers</issue_title>
<issue_description>Implement If-Modified-Since</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement If-Modified-Since for file download caching Implement HTTP caching for file downloads with If-Modified-Since Jan 23, 2026
Copilot AI requested a review from HNygard January 23, 2026 18:16
@HNygard HNygard marked this pull request as ready for review January 23, 2026 19:25
Copilot AI review requested due to automatic review settings January 23, 2026 19:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds conditional HTTP caching to /file downloads using Last-Modified/If-Modified-Since so browsers can reuse cached email bodies and attachments.

Changes:

  • Add timestamp-returning fetch helpers in ThreadStorageManager for email bodies and attachments.
  • Set Last-Modified + Cache-Control and return 304 Not Modified when If-Modified-Since indicates no change.
  • Enhance e2e test harness to send custom request headers and add coverage for 304 behavior (email body path).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
organizer/src/file.php Adds Last-Modified/If-Modified-Since handling for email body + attachment responses.
organizer/src/class/ThreadStorageManager.php Adds new DB accessors returning content plus timestamp metadata.
organizer/src/e2e-tests/pages/common/E2EPageTestCase.php Adds support for passing custom headers through the e2e HTTP client.
organizer/src/e2e-tests/pages/FilePageTest.php Adds assertions for caching headers and a 304 round-trip test for email body downloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI and others added 2 commits January 24, 2026 23:31
…dd immutable, add attachment test

Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Copilot AI requested a review from HNygard January 25, 2026 08:39
Copy link
Owner

@HNygard HNygard left a comment

Choose a reason for hiding this comment

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

LGTM. Merge and run the np run to see if this improves that performance

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For file download, implement If-Modified-Since and similar caching for browsers

2 participants