mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
MM-62156: Avoid SELECT * in retention_policy_store.go (#30458)
* MM-62156: Avoid SELECT * in retention_policy_store.go - Modified subQueryIN function to use specific column name instead of SELECT * - Improved code comments to explain the change - Maintained same functionality while avoiding SELECT * Fixes: https://mattermost.atlassian.net/browse/MM-62156 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * simplify subQueryIN comments * inline part of subQueryIN for greater clarity --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
0f860f0512
commit
949a19efc1
1 changed files with 19 additions and 11 deletions
|
|
@ -642,7 +642,8 @@ func (s *SqlRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string)
|
|||
|
||||
func subQueryIN(property string, query sq.SelectBuilder) sq.Sqlizer {
|
||||
queryString, args := query.MustSql()
|
||||
subQuery := fmt.Sprintf("%s IN (SELECT * FROM (%s) AS A)", property, queryString)
|
||||
|
||||
subQuery := fmt.Sprintf("%s IN (%s)", property, queryString)
|
||||
return sq.Expr(subQuery, args...)
|
||||
}
|
||||
|
||||
|
|
@ -650,11 +651,14 @@ func subQueryIN(property string, query sq.SelectBuilder) sq.Sqlizer {
|
|||
// where a channel or team no longer exists.
|
||||
func (s *SqlRetentionPolicyStore) DeleteOrphanedRows(limit int) (deleted int64, err error) {
|
||||
// We need the extra level of nesting to deal with MySQL's locking
|
||||
rpcSubQuery := sq.Select("ChannelId").
|
||||
From("RetentionPoliciesChannels").
|
||||
LeftJoin("Channels ON RetentionPoliciesChannels.ChannelId = Channels.Id").
|
||||
Where("Channels.Id IS NULL").
|
||||
Limit(uint64(limit))
|
||||
rpcSubQuery := sq.Select("ChannelId").FromSelect(
|
||||
sq.Select("ChannelId").
|
||||
From("RetentionPoliciesChannels").
|
||||
LeftJoin("Channels ON RetentionPoliciesChannels.ChannelId = Channels.Id").
|
||||
Where("Channels.Id IS NULL").
|
||||
Limit(uint64(limit)),
|
||||
"A",
|
||||
)
|
||||
|
||||
rpcDeleteQuery, rpcArgs, err := s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesChannels").
|
||||
|
|
@ -664,11 +668,15 @@ func (s *SqlRetentionPolicyStore) DeleteOrphanedRows(limit int) (deleted int64,
|
|||
return int64(0), errors.Wrap(err, "retention_policies_channels_tosql")
|
||||
}
|
||||
|
||||
rptSubQuery := sq.Select("TeamId").
|
||||
From("RetentionPoliciesTeams").
|
||||
LeftJoin("Teams ON RetentionPoliciesTeams.TeamId = Teams.Id").
|
||||
Where("Teams.Id IS NULL").
|
||||
Limit(uint64(limit))
|
||||
// We need the extra level of nesting to deal with MySQL's locking
|
||||
rptSubQuery := sq.Select("TeamId").FromSelect(
|
||||
sq.Select("TeamId").
|
||||
From("RetentionPoliciesTeams").
|
||||
LeftJoin("Teams ON RetentionPoliciesTeams.TeamId = Teams.Id").
|
||||
Where("Teams.Id IS NULL").
|
||||
Limit(uint64(limit)),
|
||||
"A",
|
||||
)
|
||||
|
||||
rptDeleteQuery, rptArgs, err := s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesTeams").
|
||||
|
|
|
|||
Loading…
Reference in a new issue