Skip to content
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

feat: caches weather with redis & info tooltip #358

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

ixahmedxi
Copy link
Collaborator

@ixahmedxi ixahmedxi commented Nov 7, 2023

Closes #355

This PR aims to do the following:

  • Caches the user's weather information until midnight of the current day using Redis, this will make it so that every user only sends the weather api a request every 24 hours.
  • Implements a tooltip that gives the user more insights about the weather data they are seeing and how it is calculated.
  • Removed console logs from the code in some places.
  • Improves the Logic for getting the weather data in terms of:
    • more type-safe operations, parse with zod when we can
    • more accurate way of getting low temperature

Copy link

vercel bot commented Nov 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2023 11:44pm

Copy link
Contributor

@Erb3 Erb3 left a comment

Choose a reason for hiding this comment

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

I haven't had time to test this locally, but good work! 👍

if (!cachedWeatherData) {
const weatherData = await getCurrentWeatherData(input);
const secondsUntilMidnight = Math.round(
(new Date().setHours(24, 0, 0, 0) - Date.now()) / 1000,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a quite long and confusing line. The code below isn't shorter, but it is more understandable!

import { Interval, DateTime } from "luxon"

const secondsUntilMidnight = Interval.fromDateTimes(
  DateTime.now(),
  DateTime.now().endOf("day")
).length("seconds")

Choose a reason for hiding this comment

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

I like this alternative ✅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tbh I would rather not need to install another package into the project and for maintenance sake, just use what javascript gave us out of the box, the variable naming is very descriptive of what the operation does so I don't think we necessarily need luxon.

@Erb3
Copy link
Contributor

Erb3 commented Nov 8, 2023

Closes #355, please link

Copy link

@herropaul herropaul left a comment

Choose a reason for hiding this comment

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

Looks good on my end!

@ixahmedxi ixahmedxi merged commit 7923b72 into main Nov 8, 2023
3 checks passed
@ixahmedxi ixahmedxi deleted the ahmed/weather-redis-cache branch November 8, 2023 22:30
Erb3 pushed a commit to Erb3-forked/noodle-legacy that referenced this pull request May 14, 2024
* feat: caches weather with redis & info tooltip

* refactor: literally dropped by 50 lines
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.

Cache response from yr.no
3 participants