-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update FeedItem with precalculated time values and constant categories #723
Conversation
WalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ui/src/components/Bouts/FeedItem.tsx
(3 hunks)
🧰 Additional context used
📓 Learnings (1)
ui/src/components/Bouts/FeedItem.tsx (1)
Learnt from: paulcretu
PR: orcasound/orcasite#694
File: ui/src/components/Bouts/FeedItem.tsx:36-36
Timestamp: 2024-11-12T04:20:49.636Z
Learning: DetectionCategory is a union type, not an enum; initializing arrays of DetectionCategory with string literals is valid.
🔇 Additional comments (3)
ui/src/components/Bouts/FeedItem.tsx (3)
28-28
: Great optimization!
Moving the categories array to a constant is a good optimization. Since this is a static value, it doesn't need to be recreated on each render, and removing it from useMemo reduces unnecessary overhead.
69-69
: LGTM!
The filtering logic is now more readable with the precalculated time variables.
Also applies to: 72-72
105-105
: LGTM!
The dependency array correctly includes all the variables used within the effect. Removing categories
from the dependencies is appropriate since it's now a constant.
ui/src/components/Bouts/FeedItem.tsx
Outdated
const fifteenMinutesAgo = new Date(now.valueOf() - 15 * 60 * 1000); | ||
const fiveMinutesAgo = new Date(now.valueOf() - 5 * 60 * 1000); |
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.
🛠️ Refactor suggestion
Consider using useMemo for time calculations
While extracting these calculations improves readability, they're based on now
which is only initialized once when the component mounts. For long-lived components, this could lead to stale calculations.
Consider using useMemo to keep the calculations fresh:
- const fifteenMinutesAgo = new Date(now.valueOf() - 15 * 60 * 1000);
- const fiveMinutesAgo = new Date(now.valueOf() - 5 * 60 * 1000);
+ const fifteenMinutesAgo = useMemo(() => new Date(Date.now() - 15 * 60 * 1000), []);
+ const fiveMinutesAgo = useMemo(() => new Date(Date.now() - 5 * 60 * 1000), []);
Committable suggestion skipped: line range outside the PR's diff.
Decided to implement changes suggested here #716 (comment)
Summary by CodeRabbit