mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
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:
parent
35e06a2ee8
commit
489ea1fdd6
1 changed files with 18 additions and 15 deletions
|
|
@ -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(¬iceStates, sql, args...); err != nil {
|
||||
query := s.selectQuery.
|
||||
Where(sq.Eq{"UserId": userId, "NoticeId": notices})
|
||||
|
||||
if err := transaction.SelectBuilder(¬iceStates, 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(¬iceStates, sql, args...); err != nil {
|
||||
query := s.selectQuery.Where(sq.Eq{"UserId": userId})
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(¬iceStates, query); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
|
||||
}
|
||||
return noticeStates, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue