Module project, commit, submission
All checks were successful
Build and Release / release (push) Successful in 1m15s

This commit is contained in:
2026-04-26 16:31:03 +07:00
parent ac90236022
commit 6918a100fc
60 changed files with 5957 additions and 1020 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"history-api/internal/gen/sqlc"
@@ -24,6 +25,7 @@ type WikiRepository interface {
Delete(ctx context.Context, id pgtype.UUID) error
CreateEntityWikis(ctx context.Context, params sqlc.CreateEntityWikisParams) error
BulkDeleteEntityWikisByEntityId(ctx context.Context, entityId pgtype.UUID) error
WithTx(tx pgx.Tx) WikiRepository
}
type wikiRepository struct {
@@ -38,6 +40,13 @@ func NewWikiRepository(db sqlc.DBTX, c cache.Cache) WikiRepository {
}
}
func (r *wikiRepository) WithTx(tx pgx.Tx) WikiRepository {
return &wikiRepository{
q: r.q.WithTx(tx),
c: r.c,
}
}
func (r *wikiRepository) generateQueryKey(prefix string, params any) string {
b, _ := json.Marshal(params)
hash := fmt.Sprintf("%x", md5.Sum(b))
@@ -191,11 +200,9 @@ func (r *wikiRepository) Create(ctx context.Context, params sqlc.CreateWikiParam
CreatedAt: convert.TimeToPtr(row.CreatedAt),
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
}
_ = r.c.Set(ctx, fmt.Sprintf("wiki:id:%s", wiki.ID), wiki, constants.NormalCacheDuration)
go func() {
bgCtx := context.Background()
_ = r.c.DelByPattern(bgCtx, "wiki:search*")
_ = r.c.DelByPattern(context.Background(), "wiki:search*")
}()
return &wiki, nil
@@ -214,7 +221,7 @@ func (r *wikiRepository) Update(ctx context.Context, params sqlc.UpdateWikiParam
CreatedAt: convert.TimeToPtr(row.CreatedAt),
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
}
_ = r.c.Set(ctx, fmt.Sprintf("wiki:id:%s", wiki.ID), wiki, constants.NormalCacheDuration)
_ = r.c.Del(ctx, fmt.Sprintf("wiki:id:%s", wiki.ID))
return &wiki, nil
}
@@ -224,9 +231,6 @@ func (r *wikiRepository) Delete(ctx context.Context, id pgtype.UUID) error {
return err
}
_ = r.c.Del(ctx, fmt.Sprintf("wiki:id:%s", convert.UUIDToString(id)))
go func() {
_ = r.c.DelByPattern(context.Background(), "wiki:search*")
}()
return nil
}