Skip to content

Commit

Permalink
perf: remove unnecessary sql filter
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Nov 25, 2024
1 parent b0d5e5a commit f93cd3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 1 addition & 7 deletions internal/search/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ func (c *client) Handle(ctx echo.Context) error {
}
ids := slice.Map(hits, func(h hit) model.SubjectID { return h.ID })

var sf = subject.Filter{}

if r.Filter.NSFW.Set && !r.Filter.NSFW.Value {
sf.NSFW = null.Bool{Set: true, Value: false}
}

subjects, err := c.subjectRepo.GetByIDs(ctx.Request().Context(), ids, sf)
subjects, err := c.subjectRepo.GetByIDs(ctx.Request().Context(), ids, subject.Filter{})
if err != nil {
return errgo.Wrap(err, "subjectRepo.GetByIDs")
}
Expand Down
9 changes: 4 additions & 5 deletions internal/tag/cache_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/bangumi/server/internal/pkg/cache"
)

const cacheTTL = time.Hour * 4

func NewCachedRepo(c cache.RedisCache, r Repo, log *zap.Logger) CachedRepo {
return cacheRepo{cache: c, repo: r, log: log.Named("subject.CachedRepo")}
}
Expand Down Expand Up @@ -89,10 +91,7 @@ func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) {
return tags, err
}

if e := r.cache.Set(ctx, key, cachedTags{
ID: id,
Tags: tags,
}, time.Hour); e != nil {
if e := r.cache.Set(ctx, key, cachedTags{ID: id, Tags: tags}, cacheTTL); e != nil {
r.log.Error("can't set response to cache", zap.Error(e))
}

Expand Down Expand Up @@ -141,7 +140,7 @@ func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[mod
err = r.cache.Set(ctx, cachekey.SubjectMetaTag(id), cachedTags{
ID: id,
Tags: tag,
}, time.Hour)
}, cacheTTL)
if err != nil {
return nil, errgo.Wrap(err, "cache.Set")
}
Expand Down

0 comments on commit f93cd3d

Please sign in to comment.