feat: implement core repository layer and redis caching infrastructure
Build and Release / release (push) Successful in 1m37s
Build and Release / release (push) Successful in 1m37s
This commit is contained in:
@@ -47,6 +47,7 @@ func NewHttpServer() *FiberServer {
|
||||
|
||||
server.App.Use(swagger.New(cfg))
|
||||
|
||||
if os.Getenv("DISABLE_REQUEST_LOG") != "true" {
|
||||
logger := zerolog.New(zerolog.ConsoleWriter{
|
||||
Out: os.Stderr,
|
||||
TimeFormat: time.RFC3339,
|
||||
@@ -54,6 +55,7 @@ func NewHttpServer() *FiberServer {
|
||||
server.App.Use(middleware.New(middleware.Config{
|
||||
Logger: &logger,
|
||||
}))
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ services:
|
||||
image: redis:8.6.2-alpine
|
||||
container_name: history_cache
|
||||
restart: unless-stopped
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
command: ["redis-server", "--appendonly", "no"]
|
||||
volumes:
|
||||
- history_cache_data:/data
|
||||
networks:
|
||||
|
||||
@@ -143,7 +143,11 @@ func (r *battleReplayRepository) GetByID(ctx context.Context, id pgtype.UUID) (*
|
||||
func (r *battleReplayRepository) GetByGeometryID(ctx context.Context, geometryID pgtype.UUID) ([]*models.BattleReplayEntity, error) {
|
||||
cacheKey := fmt.Sprintf("battle_replay:geometry:%s", convert.UUIDToString(geometryID))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.BattleReplayEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -208,7 +212,11 @@ func (r *battleReplayRepository) GetByGeometryIDs(ctx context.Context, geometryI
|
||||
func (r *battleReplayRepository) GetByProjectID(ctx context.Context, projectID pgtype.UUID) ([]*models.BattleReplayEntity, error) {
|
||||
cacheKey := fmt.Sprintf("battle_replay:project:%s", convert.UUIDToString(projectID))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.BattleReplayEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,11 @@ func (r *chatRepository) CreateMessage(ctx context.Context, params sqlc.CreateMe
|
||||
func (r *chatRepository) GetMessagesByConversation(ctx context.Context, params sqlc.GetMessagesByConversationParams) ([]*models.MessageEntity, error) {
|
||||
queryKey := r.generateQueryKey("message:conversation", 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.MessageEntity{}, nil
|
||||
}
|
||||
return r.getMessagesByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -315,9 +319,7 @@ func (r *chatRepository) GetMessagesByConversation(ctx context.Context, params s
|
||||
if len(toCache) > 0 {
|
||||
_ = r.c.MSet(ctx, toCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
@@ -354,7 +356,11 @@ func (r *chatRepository) GetChatbotHistory(ctx context.Context, params sqlc.GetC
|
||||
convert.UUIDToString(params.CursorID),
|
||||
)
|
||||
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.ChatbotHistoryEntity{}, nil
|
||||
}
|
||||
return r.getChatbotHistoriesByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -383,9 +389,7 @@ func (r *chatRepository) GetChatbotHistory(ctx context.Context, params sqlc.GetC
|
||||
if len(toCache) > 0 {
|
||||
_ = r.c.MSet(ctx, toCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
@@ -165,7 +165,11 @@ func (r *commitRepository) getByIDsWithFallback(ctx context.Context, ids []strin
|
||||
func (r *commitRepository) GetByProjectID(ctx context.Context, projectID pgtype.UUID) ([]*models.CommitEntity, error) {
|
||||
queryKey := fmt.Sprintf("commit:project:%s", convert.UUIDToString(projectID))
|
||||
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.CommitEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -175,8 +179,10 @@ func (r *commitRepository) GetByProjectID(ctx context.Context, projectID pgtype.
|
||||
}
|
||||
|
||||
entities := make([]*models.CommitEntity, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
entities = append(entities, &models.CommitEntity{
|
||||
ids := make([]string, len(rows))
|
||||
commitToCache := make(map[string]any)
|
||||
for i, row := range rows {
|
||||
item := &models.CommitEntity{
|
||||
ID: convert.UUIDToString(row.ID),
|
||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||
SnapshotJson: row.SnapshotJson,
|
||||
@@ -185,15 +191,26 @@ func (r *commitRepository) GetByProjectID(ctx context.Context, projectID pgtype.
|
||||
EditSummary: convert.TextToString(row.EditSummary),
|
||||
IsDeleted: row.IsDeleted,
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
})
|
||||
}
|
||||
entities = append(entities, item)
|
||||
ids[i] = item.ID
|
||||
commitToCache[fmt.Sprintf("commit:id:%s", item.ID)] = item
|
||||
}
|
||||
if len(commitToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, commitToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
func (r *commitRepository) Search(ctx context.Context, params sqlc.SearchCommitsParams) ([]*models.CommitEntity, error) {
|
||||
queryKey := r.generateQueryKey("commit: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.CommitEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
rows, err := r.q.SearchCommits(ctx, params)
|
||||
@@ -223,9 +240,7 @@ func (r *commitRepository) Search(ctx context.Context, params sqlc.SearchCommits
|
||||
if len(commitToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, commitToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return commits, nil
|
||||
}
|
||||
|
||||
@@ -163,7 +163,11 @@ func (r *entityRepository) GetByID(ctx context.Context, id pgtype.UUID) (*models
|
||||
func (r *entityRepository) Search(ctx context.Context, params sqlc.SearchEntitiesParams) ([]*models.EntityEntity, error) {
|
||||
queryKey := r.generateQueryKey("entity: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.EntityEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -198,9 +202,7 @@ func (r *entityRepository) Search(ctx context.Context, params sqlc.SearchEntitie
|
||||
_ = r.c.MSet(ctx, entityToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return entities, nil
|
||||
}
|
||||
@@ -263,7 +265,11 @@ func (r *entityRepository) Delete(ctx context.Context, id pgtype.UUID) error {
|
||||
func (r *entityRepository) GetByProjectID(ctx context.Context, projectID pgtype.UUID) ([]*models.EntityEntity, error) {
|
||||
cacheKey := fmt.Sprintf("entity:project:%s", convert.UUIDToString(projectID))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.EntityEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,11 @@ func (r *geometryRepository) GetByID(ctx context.Context, id pgtype.UUID) (*mode
|
||||
func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeometriesParams) ([]*models.GeometryEntity, error) {
|
||||
queryKey := r.generateQueryKey("geometry: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.GeometryEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -221,9 +225,7 @@ func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeome
|
||||
if len(geometryToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, geometryToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return geometries, nil
|
||||
}
|
||||
@@ -311,7 +313,11 @@ func (r *geometryRepository) BulkDeleteEntityGeometriesByEntityId(ctx context.Co
|
||||
func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtype.UUID) ([]*models.GeometryEntity, error) {
|
||||
cacheKey := fmt.Sprintf("geometry:project:%s", convert.UUIDToString(projectID))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.GeometryEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -359,7 +365,11 @@ func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtyp
|
||||
func (r *geometryRepository) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype.UUID) ([]*models.GeometryEntity, error) {
|
||||
cacheKey := fmt.Sprintf("geometry:bound_with:%s", convert.UUIDToString(boundWith))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.GeometryEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -511,7 +521,11 @@ func (r *geometryRepository) SearchByEntityName(ctx context.Context, params sqlc
|
||||
|
||||
queryKey := r.generateQueryKey("geometry:search:entity", params)
|
||||
var cachedPairs []string
|
||||
if err := r.c.Get(ctx, queryKey, &cachedPairs); err == nil && len(cachedPairs) > 0 {
|
||||
err := r.c.Get(ctx, queryKey, &cachedPairs)
|
||||
if err == nil {
|
||||
if len(cachedPairs) == 0 {
|
||||
return []*models.EntityGeometriesSearchEntity{}, nil
|
||||
}
|
||||
return r.getSearchByIDsWithFallback(ctx, cachedPairs)
|
||||
}
|
||||
|
||||
@@ -544,9 +558,7 @@ func (r *geometryRepository) SearchByEntityName(ctx context.Context, params sqlc
|
||||
if len(geometryToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, geometryToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(pairs) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, pairs, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return geometries, nil
|
||||
}
|
||||
|
||||
@@ -216,7 +216,11 @@ func (r *mediaRepository) BulkDelete(ctx context.Context, ids []pgtype.UUID) err
|
||||
func (r *mediaRepository) Search(ctx context.Context, params sqlc.SearchMediasParams) ([]*models.MediaEntity, error) {
|
||||
queryKey := r.generateQueryKey("media: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.MediaEntity{}, nil
|
||||
}
|
||||
listItem, err := r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -259,9 +263,7 @@ func (r *mediaRepository) Search(ctx context.Context, params sqlc.SearchMediasPa
|
||||
_ = r.c.MSet(ctx, mediasToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return medias, nil
|
||||
}
|
||||
@@ -284,7 +286,11 @@ func (r *mediaRepository) Count(ctx context.Context, params sqlc.CountMediasPara
|
||||
func (r *mediaRepository) GetByUserID(ctx context.Context, userId pgtype.UUID) ([]*models.MediaEntity, error) {
|
||||
queryKey := fmt.Sprintf("media:userId:%s", convert.UUIDToString(userId))
|
||||
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.MediaEntity{}, nil
|
||||
}
|
||||
listItem, err := r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -327,9 +333,7 @@ func (r *mediaRepository) GetByUserID(ctx context.Context, userId pgtype.UUID) (
|
||||
_ = r.c.MSet(ctx, mediasToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return medias, nil
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
@@ -215,7 +215,11 @@ func (r *roleRepository) Update(ctx context.Context, params sqlc.UpdateRoleParam
|
||||
func (r *roleRepository) All(ctx context.Context) ([]*models.RoleEntity, error) {
|
||||
queryKey := "role:all"
|
||||
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.RoleEntity{}, nil
|
||||
}
|
||||
listItem, err := r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -254,9 +258,7 @@ func (r *roleRepository) All(ctx context.Context) ([]*models.RoleEntity, error)
|
||||
_ = r.c.MSet(ctx, roleToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return roles, nil
|
||||
}
|
||||
|
||||
@@ -138,7 +138,11 @@ func (r *statisticRepository) Search(ctx context.Context, params sqlc.SearchSyst
|
||||
queryKey := r.generateQueryKey("statistic: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.StatisticEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -161,9 +165,7 @@ func (r *statisticRepository) Search(ctx context.Context, params sqlc.SearchSyst
|
||||
if len(statsToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, statsToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
@@ -166,7 +166,11 @@ func (r *submissionRepository) GetByIDs(ctx context.Context, ids []string) ([]*m
|
||||
func (r *submissionRepository) Search(ctx context.Context, params sqlc.SearchSubmissionsParams) ([]*models.SubmissionEntity, error) {
|
||||
queryKey := r.generateQueryKey("verification: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.SubmissionEntity{}, nil
|
||||
}
|
||||
listItem, err := r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -216,9 +220,7 @@ func (r *submissionRepository) Search(ctx context.Context, params sqlc.SearchSub
|
||||
_ = r.c.MSet(ctx, itemToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@@ -313,7 +313,11 @@ func (r *userRepository) Search(ctx context.Context, params sqlc.SearchUsersPara
|
||||
queryKey := r.generateQueryKey("user: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.UserEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -354,9 +358,7 @@ func (r *userRepository) Search(ctx context.Context, params sqlc.SearchUsersPara
|
||||
if len(usersToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, usersToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
||||
@@ -278,7 +278,11 @@ func (v *verificationRepository) DeleteVerificationMedia(ctx context.Context, pa
|
||||
func (v *verificationRepository) GetByUserID(ctx context.Context, userId pgtype.UUID) ([]*models.UserVerificationEntity, error) {
|
||||
queryKey := fmt.Sprintf("verification:userId:%s", convert.UUIDToString(userId))
|
||||
var cachedIDs []string
|
||||
if err := v.c.Get(ctx, queryKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := v.c.Get(ctx, queryKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.UserVerificationEntity{}, nil
|
||||
}
|
||||
listItem, err := v.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -332,9 +336,7 @@ func (v *verificationRepository) GetByUserID(ctx context.Context, userId pgtype.
|
||||
_ = v.c.MSet(ctx, itemToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = v.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
@@ -342,7 +344,11 @@ func (v *verificationRepository) GetByUserID(ctx context.Context, userId pgtype.
|
||||
func (v *verificationRepository) Search(ctx context.Context, params sqlc.SearchUserVerificationsParams) ([]*models.UserVerificationEntity, error) {
|
||||
queryKey := v.generateQueryKey("verification:search", params)
|
||||
var cachedIDs []string
|
||||
if err := v.c.Get(ctx, queryKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := v.c.Get(ctx, queryKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.UserVerificationEntity{}, nil
|
||||
}
|
||||
listItem, err := v.getByIDsWithFallback(ctx, cachedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -397,9 +403,7 @@ func (v *verificationRepository) Search(ctx context.Context, params sqlc.SearchU
|
||||
_ = v.c.MSet(ctx, itemToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
_ = v.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@@ -190,7 +190,11 @@ func (r *wikiRepository) GetByID(ctx context.Context, id pgtype.UUID) (*models.W
|
||||
func (r *wikiRepository) Search(ctx context.Context, params sqlc.SearchWikisParams) ([]*models.WikiEntity, error) {
|
||||
queryKey := r.generateQueryKey("wiki: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.WikiEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -242,9 +246,7 @@ func (r *wikiRepository) Search(ctx context.Context, params sqlc.SearchWikisPara
|
||||
if len(wikiToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, wikiToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return wikis, nil
|
||||
}
|
||||
@@ -315,7 +317,11 @@ func (r *wikiRepository) BulkDeleteEntityWikisByEntityId(ctx context.Context, en
|
||||
func (r *wikiRepository) GetByProjectID(ctx context.Context, projectID pgtype.UUID) ([]*models.WikiEntity, error) {
|
||||
cacheKey := fmt.Sprintf("wiki:project:%s", convert.UUIDToString(projectID))
|
||||
var cachedIDs []string
|
||||
if err := r.c.Get(ctx, cacheKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
||||
err := r.c.Get(ctx, cacheKey, &cachedIDs)
|
||||
if err == nil {
|
||||
if len(cachedIDs) == 0 {
|
||||
return []*models.WikiEntity{}, nil
|
||||
}
|
||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
||||
}
|
||||
|
||||
@@ -368,9 +374,7 @@ func (r *wikiRepository) GetByProjectID(ctx context.Context, projectID pgtype.UU
|
||||
if len(wikiToCache) > 0 {
|
||||
_ = r.c.MSet(ctx, wikiToCache, constants.NormalCacheDuration)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
_ = r.c.Set(ctx, cacheKey, ids, constants.ListCacheDuration)
|
||||
}
|
||||
|
||||
return wikis, nil
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -35,7 +35,8 @@ func NewRedisClient() (Cache, error) {
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: uri,
|
||||
MinIdleConns: 10,
|
||||
PoolSize: 500,
|
||||
MinIdleConns: 50,
|
||||
DialTimeout: 5 * time.Second,
|
||||
ReadTimeout: 3 * time.Second,
|
||||
WriteTimeout: 3 * time.Second,
|
||||
|
||||
@@ -20,6 +20,8 @@ func NewPostgresqlDB() (*pgxpool.Pool, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
poolConfig.MaxConns = 100
|
||||
poolConfig.MinConns = 10
|
||||
|
||||
var pool *pgxpool.Pool
|
||||
|
||||
|
||||
Reference in New Issue
Block a user