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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
35e06a2ee8
Коммит
489ea1fdd6
@@ -15,10 +15,20 @@ import (
|
|||||||
|
|
||||||
type SqlProductNoticesStore struct {
|
type SqlProductNoticesStore struct {
|
||||||
*SqlStore
|
*SqlStore
|
||||||
|
|
||||||
|
selectQuery sq.SelectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSqlProductNoticesStore(sqlStore *SqlStore) store.ProductNoticesStore {
|
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 {
|
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)
|
defer finalizeTransactionX(transaction, &err)
|
||||||
|
|
||||||
noticeStates := []model.ProductNoticeViewState{}
|
noticeStates := []model.ProductNoticeViewState{}
|
||||||
sql, args, err := s.getQueryBuilder().
|
query := s.selectQuery.
|
||||||
Select("*").
|
Where(sq.Eq{"UserId": userId, "NoticeId": notices})
|
||||||
From("ProductNoticeViewState").
|
|
||||||
Where(sq.And{sq.Eq{"UserId": userId}, sq.Eq{"NoticeId": notices}}).
|
if err := transaction.SelectBuilder(¬iceStates, query); err != nil {
|
||||||
ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "View_ToSql")
|
|
||||||
}
|
|
||||||
if err := transaction.Select(¬iceStates, sql, args...); err != nil {
|
|
||||||
return errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
|
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) {
|
func (s SqlProductNoticesStore) GetViews(userId string) ([]model.ProductNoticeViewState, error) {
|
||||||
noticeStates := []model.ProductNoticeViewState{}
|
noticeStates := []model.ProductNoticeViewState{}
|
||||||
sql, args, err := s.getQueryBuilder().Select("*").From("ProductNoticeViewState").Where(sq.Eq{"UserId": userId}).ToSql()
|
query := s.selectQuery.Where(sq.Eq{"UserId": userId})
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "product_notice_view_state_tosql")
|
if err := s.GetReplica().SelectBuilder(¬iceStates, query); err != nil {
|
||||||
}
|
|
||||||
if err := s.GetReplica().Select(¬iceStates, sql, args...); err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
|
return nil, errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
|
||||||
}
|
}
|
||||||
return noticeStates, nil
|
return noticeStates, nil
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user