From 89ccbf255871211c7449733424b0e7b61ed33adf Mon Sep 17 00:00:00 2001 From: Joscha Henningsen Date: Fri, 8 Nov 2024 11:06:57 +0100 Subject: [PATCH] extract cacheKey to variable --- server/backend/movie.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/backend/movie.go b/server/backend/movie.go index 939bc575..ca92af1b 100644 --- a/server/backend/movie.go +++ b/server/backend/movie.go @@ -44,7 +44,8 @@ func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest } func (s *CampusServer) getMovies(ctx context.Context, lastID int32, oldestDateAt time.Time) ([]model.Movie, error) { - if movies, ok := s.moviesCache.Get(fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second())); ok { + cacheKey := fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second()) + if movies, ok := s.moviesCache.Get(cacheKey); ok { return movies, nil } var movies []model.Movie @@ -58,6 +59,6 @@ func (s *CampusServer) getMovies(ctx context.Context, lastID int32, oldestDateAt log.WithError(err).Error("Error while fetching movies from database") return nil, status.Error(codes.Internal, "Error while fetching movies from database") } - s.moviesCache.Add(fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second()), movies) + s.moviesCache.Add(cacheKey, movies) return movies, nil }