feat: implement core repository layer and redis caching infrastructure
Build and Release / release (push) Successful in 1m37s

This commit is contained in:
2026-06-03 22:15:27 +07:00
parent 4676e21740
commit dfe34b0029
17 changed files with 164 additions and 90 deletions
+12 -8
View File
@@ -172,7 +172,11 @@ func (r *projectRepository) GetByID(ctx context.Context, id pgtype.UUID) (*model
func (r *projectRepository) GetByUserID(ctx context.Context, params sqlc.GetProjectsByUserIdParams) ([]*models.ProjectEntity, error) {
queryKey := r.generateQueryKey("project:user", params)
var cachedIDs []string
if err := r.c.Get(ctx, queryKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
err := r.c.Get(ctx, queryKey, &cachedIDs)
if err == nil {
if len(cachedIDs) == 0 {
return []*models.ProjectEntity{}, nil
}
return r.getByIDsWithFallback(ctx, cachedIDs)
}
@@ -211,9 +215,7 @@ func (r *projectRepository) GetByUserID(ctx context.Context, params sqlc.GetProj
if len(projectToCache) > 0 {
_ = r.c.MSet(ctx, projectToCache, constants.NormalCacheDuration)
}
if len(ids) > 0 {
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
}
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
return projects, nil
}
@@ -221,7 +223,11 @@ func (r *projectRepository) GetByUserID(ctx context.Context, params sqlc.GetProj
func (r *projectRepository) Search(ctx context.Context, params sqlc.SearchProjectsParams) ([]*models.ProjectEntity, error) {
queryKey := r.generateQueryKey("project:search", params)
var cachedIDs []string
if err := r.c.Get(ctx, queryKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
err := r.c.Get(ctx, queryKey, &cachedIDs)
if err == nil {
if len(cachedIDs) == 0 {
return []*models.ProjectEntity{}, nil
}
return r.getByIDsWithFallback(ctx, cachedIDs)
}
@@ -259,9 +265,7 @@ func (r *projectRepository) Search(ctx context.Context, params sqlc.SearchProjec
if len(projectToCache) > 0 {
_ = r.c.MSet(ctx, projectToCache, constants.NormalCacheDuration)
}
if len(ids) > 0 {
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
}
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
return projects, nil
}