Repository navigation
fixTimezoneShift: cache the Intl.DateTimeFormat instance - #46
Merged
Merged
Conversation
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
force-pushed
the
claude/fix-timezone-shift-perf
branch
from
September 2, 2026 09:02
f273407 to
77bf463
Compare
There was a problem hiding this comment.
🟡 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
fixTimezoneShiftutilities to reinterpret legacy timestamps and bulk-update affected rows. - Cache
Intl.DateTimeFormatper timezone to avoid repeated formatter construction during offset calculations. - Wire an admin-only
fixTimezoneShiftdoActionintoBaseEntityService, 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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses a Copilot review finding on buzz-code/react-admin-nestjs#167 (submodule bump PR for #45):
getTimeZoneOffsetMinutesconstructed a freshIntl.DateTimeFormaton every call — up to 3 times per date column per row infixTimezoneShift's bulk loop. The formatter is stateless across the dates it formats, so this is unnecessary work on large selections.Change
Cache one
Intl.DateTimeFormatinstance per timezone (module-levelMap) instead of constructing a new one each call.Testing
fixTimezoneShift.util.spec.ts— passing (verified via the consumingreact-admin-nestjs/serverworkspace)react-admin-nestjs/server: full suite (115/115) andyarn build— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01KeX6BFe7P4pHLPm3VwFjPn
Generated by Claude Code