fix: address code review findings
This commit is contained in:
17
internal/cache/preferences.go
vendored
17
internal/cache/preferences.go
vendored
@@ -107,15 +107,6 @@ func (p *Preferences) AddSavedCity(ctx context.Context, userID, cityCode, cityNa
|
||||
|
||||
// RemoveSavedCity removes a city from the user's saved cities.
|
||||
func (p *Preferences) RemoveSavedCity(ctx context.Context, userID, cityCode string) error {
|
||||
key := &CacheKey{
|
||||
Kind: "prefs:saved_city:" + userID,
|
||||
Code: userID,
|
||||
From: "",
|
||||
To: "",
|
||||
Date: "",
|
||||
Request: "",
|
||||
}
|
||||
|
||||
// Load existing cities
|
||||
cities, err := p.GetSavedCities(ctx, userID)
|
||||
if err != nil {
|
||||
@@ -132,6 +123,10 @@ func (p *Preferences) RemoveSavedCity(ctx context.Context, userID, cityCode stri
|
||||
|
||||
if len(result) == 0 {
|
||||
// If no cities left, delete the key
|
||||
key := &CacheKey{
|
||||
Kind: "prefs:saved_city:" + userID,
|
||||
Code: userID,
|
||||
}
|
||||
return p.store.Delete(ctx, key)
|
||||
}
|
||||
|
||||
@@ -141,6 +136,10 @@ func (p *Preferences) RemoveSavedCity(ctx context.Context, userID, cityCode stri
|
||||
return err
|
||||
}
|
||||
|
||||
key := &CacheKey{
|
||||
Kind: "prefs:saved_city:" + userID,
|
||||
Code: userID,
|
||||
}
|
||||
return p.store.Set(ctx, key, data, PreferenceTTL)
|
||||
}
|
||||
|
||||
|
||||
5
internal/cache/store.go
vendored
5
internal/cache/store.go
vendored
@@ -167,6 +167,11 @@ func GetSearchKey(from, to, date string) *CacheKey {
|
||||
return &CacheKey{Kind: "search", From: from, To: to, Date: date}
|
||||
}
|
||||
|
||||
// GetSearchKeyWithFarTerm returns the cache key for a search query with far-term flag.
|
||||
func GetSearchKeyWithFarTerm(from, to, date, farTermFlag string) *CacheKey {
|
||||
return &CacheKey{Kind: "search", From: from, To: to, Date: date, Request: farTermFlag}
|
||||
}
|
||||
|
||||
// CacheAside represents the cache-aside pattern implementation.
|
||||
// It follows the pattern: Redis → miss → Postgres/API → write-back to Redis.
|
||||
type CacheAside struct {
|
||||
|
||||
Reference in New Issue
Block a user