Skip to content

fixTimezoneShift: cache the Intl.DateTimeFormat instance - #46

Merged
buzz-code merged 1 commit into
mainfrom
claude/fix-timezone-shift-perf
Sep 2, 2026
Merged

buzz-code merged 1 commit into
mainfrom
claude/fix-timezone-shift-perf

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Summary

Addresses a Copilot review finding on buzz-code/react-admin-nestjs#167 (submodule bump PR for #45): getTimeZoneOffsetMinutes constructed a fresh Intl.DateTimeFormat on every call — up to 3 times per date column per row in fixTimezoneShift's bulk loop. The formatter is stateless across the dates it formats, so this is unnecessary work on large selections.

Change

Cache one Intl.DateTimeFormat instance per timezone (module-level Map) instead of constructing a new one each call.

Testing

  • fixTimezoneShift.util.spec.ts — passing (verified via the consuming react-admin-nestjs/server workspace)
  • react-admin-nestjs/server: full suite (115/115) and yarn build — clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn


Generated by Claude Code

Copilot AI lite review requested due to automatic review settings September 2, 2026 09:01
Addresses a Copilot review finding on buzz-code/react-admin-nestjs#167:
getTimeZoneOffsetMinutes constructed a fresh Intl.DateTimeFormat on every
call (up to 3x per date column per row), which is comparatively expensive
and unnecessary since the formatter is stateless across the dates it
formats. Cache one instance per timezone instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn
@buzz-code
buzz-code force-pushed the claude/fix-timezone-shift-perf branch from f273407 to 77bf463 Compare September 2, 2026 09:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The PR scope/title doesn’t match the included changes, and there’s a user-facing Hebrew message that needs singular/plural correction (with aligned test expectation).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the shared server library to support remediation of legacy MySQL timezone-shifted createdAt/updatedAt values, and optimizes the remediation logic by caching Intl.DateTimeFormat instances per timezone to reduce per-row overhead during bulk processing.

Changes:

  • Add fixTimezoneShift utilities to reinterpret legacy timestamps and bulk-update affected rows.
  • Cache Intl.DateTimeFormat per timezone to avoid repeated formatter construction during offset calculations.
  • Wire an admin-only fixTimezoneShift doAction into BaseEntityService, and pin the MySQL connection timezone to UTC.
File summaries
File Description
utils/entity/fixTimezoneShift.util.ts Implements timezone-shift reinterpretation and bulk correction; adds per-timezone cached Intl.DateTimeFormat.
utils/entity/tests/fixTimezoneShift.util.spec.ts Adds unit tests for DST-aware reinterpretation and bulk-update behavior.
config/database.config.ts Pins MySQL connection to UTC (timezone: 'Z') to prevent future shifts.
base-entity/base-entity.service.ts Adds an admin-only fixTimezoneShift action handler and delegates to the util.
base-entity/tests/base-entity.service.spec.ts Adds coverage for the new doAction branch and its authorization/short-circuit behavior.
Review details

Suppressed comments (1)

utils/entity/fixTimezoneShift.util.ts:123

  • The returned message always uses the plural form "רשומות"; for a single fixed row this produces grammatically incorrect output (e.g. "תוקנו 1 רשומות"). Consider simple singular/plural handling so UI messages read correctly.
  return `תוקנו ${fixedCount} רשומות`;
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +41 to +44
// Intl.DateTimeFormat construction is comparatively expensive and stateless across
// the dates it formats, so it's built once per timezone and reused - fixTimezoneShift
// calls this up to 3 times per date column, per row.
const timeZoneFormatters = new Map<string, Intl.DateTimeFormat>();
@buzz-code
buzz-code merged commit d13f7c2 into main Sep 2, 2026
buzz-code pushed a commit to buzz-code/react-admin-nestjs that referenced this pull request Sep 2, 2026
Picks up:
- buzz-code/nra-server#46: cache the Intl.DateTimeFormat instance in
  fixTimezoneShift (was constructed fresh up to 3x per date column per
  row)
- buzz-code/nra-client#44: BulkFixTimezoneShiftButton now confirms
  before firing (was immediate on click)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn
buzz-code added a commit to buzz-code/react-admin-nestjs that referenced this pull request Sep 2, 2026
…167)

* Bump client/shared and server/shared: admin-only timezone-fix action

Picks up:
- buzz-code/nra-server#45: generic admin-only 'fixTimezoneShift' doAction
  on BaseEntityService, correcting createdAt/updatedAt for rows written
  before the mysql connection was pinned to UTC (nra-server#44)
- buzz-code/nra-client#43: matching admin-only bulk action button,
  auto-offered on any list whose rows carry createdAt/updatedAt

No per-entity wiring needed on either side - every list backed by
BaseEntityService with createdAt/updatedAt (att_report, klass, student,
teacher, ...) picks this up automatically.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn

* Bump client/shared and server/shared: address Copilot review findings

Picks up:
- buzz-code/nra-server#46: cache the Intl.DateTimeFormat instance in
  fixTimezoneShift (was constructed fresh up to 3x per date column per
  row)
- buzz-code/nra-client#44: BulkFixTimezoneShiftButton now confirms
  before firing (was immediate on click)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

3 participants