Remove SELECT * from product notices store (#31246)

* Remove SELECT * from product notices store

Replace wildcard selects with explicit column names and use SelectBuilder pattern for consistency with other stores.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update server/channels/store/sqlstore/product_notices_store.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Jesse Hallam 2025-05-31 06:23:42 -03:00 committed by GitHub
parent 35e06a2ee8
commit 489ea1fdd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,10 +15,20 @@ import (
type SqlProductNoticesStore struct {
*SqlStore
selectQuery sq.SelectBuilder
}
func newSqlProductNoticesStore(sqlStore *SqlStore) store.ProductNoticesStore {
return &SqlProductNoticesStore{sqlStore}
s := &SqlProductNoticesStore{
SqlStore: sqlStore,
}
s.selectQuery = s.getQueryBuilder().
Select("UserId", "NoticeId", "Viewed", "Timestamp").
From("ProductNoticeViewState")
return s
}
func (s SqlProductNoticesStore) Clear(notices []string) error {
@ -57,15 +67,10 @@ func (s SqlProductNoticesStore) View(userId string, notices []string) (err error
defer finalizeTransactionX(transaction, &err)
noticeStates := []model.ProductNoticeViewState{}
sql, args, err := s.getQueryBuilder().
Select("*").
From("ProductNoticeViewState").
Where(sq.And{sq.Eq{"UserId": userId}, sq.Eq{"NoticeId": notices}}).
ToSql()
if err != nil {
return errors.Wrap(err, "View_ToSql")
}
if err := transaction.Select(&noticeStates, sql, args...); err != nil {
query := s.selectQuery.
Where(sq.Eq{"UserId": userId, "NoticeId": notices})
if err := transaction.SelectBuilder(&noticeStates, query); err != nil {
return errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
}
@ -115,11 +120,9 @@ func (s SqlProductNoticesStore) View(userId string, notices []string) (err error
func (s SqlProductNoticesStore) GetViews(userId string) ([]model.ProductNoticeViewState, error) {
noticeStates := []model.ProductNoticeViewState{}
sql, args, err := s.getQueryBuilder().Select("*").From("ProductNoticeViewState").Where(sq.Eq{"UserId": userId}).ToSql()
if err != nil {
return nil, errors.Wrap(err, "product_notice_view_state_tosql")
}
if err := s.GetReplica().Select(&noticeStates, sql, args...); err != nil {
query := s.selectQuery.Where(sq.Eq{"UserId": userId})
if err := s.GetReplica().SelectBuilder(&noticeStates, query); err != nil {
return nil, errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
}
return noticeStates, nil