Removing remaining instances of GetReplica/GetMaster (#19773)

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-03-15 11:14:33 +05:30
коммит произвёл GitHub
родитель f4f8dcc88b
Коммит 9d10199e5f
5 изменённых файлов: 38 добавлений и 31 удалений

Просмотреть файл

@@ -435,7 +435,6 @@ func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, cate
}
func (s SqlChannelStore) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, error) {
var categories []*sidebarCategoryForJoin
sql, args, err := s.getQueryBuilder().
Select("SidebarCategories.*", "SidebarChannels.ChannelId").
From("SidebarCategories").
@@ -446,7 +445,8 @@ func (s SqlChannelStore) GetSidebarCategory(categoryId string) (*model.SidebarCa
return nil, errors.Wrap(err, "sidebar_category_tosql")
}
if _, err = s.GetReplica().Select(&categories, sql, args...); err != nil {
categories := []*sidebarCategoryForJoin{}
if err = s.GetReplicaX().Select(&categories, sql, args...); err != nil {
return nil, store.NewErrNotFound("SidebarCategories", categoryId)
}

Просмотреть файл

@@ -1498,34 +1498,36 @@ func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int,
if len(roots) == 0 {
return nil, nil
}
// TODO: convert to squirrel HW
params := make(map[string]interface{})
placeholders := make([]string, len(roots))
for idx, r := range roots {
key := fmt.Sprintf(":Root%v", idx)
params[key[1:]] = r
placeholders[idx] = key
}
placeholderString := strings.Join(placeholders, ", ")
params["ChannelId"] = channelId
replyCountQuery := ""
whereStatement := "p.Id IN (" + placeholderString + ")"
cols := []string{"p.*"}
var where sq.Sqlizer
where = sq.Eq{"p.Id": roots}
if skipFetchThreads {
replyCountQuery = `, (SELECT COUNT(*) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount`
cols = append(cols, "(SELECT COUNT(*) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount")
} else {
whereStatement += " OR p.RootId IN (" + placeholderString + ")"
where = sq.Or{
where,
sq.Eq{"p.RootId": roots},
}
}
var posts []*model.Post
_, err = s.GetReplica().Select(&posts, `
SELECT p.*`+replyCountQuery+`
FROM
Posts p
WHERE
(`+whereStatement+`)
AND ChannelId = :ChannelId
AND DeleteAt = 0
ORDER BY CreateAt`,
params)
query := s.getQueryBuilder().
Select(cols...).
From("Posts p").
Where(sq.And{
where,
sq.Eq{"ChannelId": channelId},
sq.Eq{"DeleteAt": 0},
}).
OrderBy("CreateAt")
sql, args, err := query.ToSql()
if err != nil {
return nil, errors.Wrap(err, "ParentPosts_Tosql")
}
posts := []*model.Post{}
err = s.GetReplicaX().Select(&posts, sql, args...)
if err != nil {
return nil, errors.Wrap(err, "failed to find Posts")
}

Просмотреть файл

@@ -74,6 +74,10 @@ func newSqlxDBWrapper(db *sqlx.DB, timeout time.Duration, trace bool) *sqlxDBWra
}
}
func (w *sqlxDBWrapper) Stats() sql.DBStats {
return w.DB.Stats()
}
func (w *sqlxDBWrapper) Beginx() (*sqlxTxWrapper, error) {
tx, err := w.DB.Beginx()
if err != nil {

Просмотреть файл

@@ -376,7 +376,8 @@ func (ss *SqlStore) GetDbVersion(numerical bool) (string, error) {
return "", errors.New("Not supported driver")
}
version, err := ss.GetReplica().SelectStr(sqlVersion)
var version string
err := ss.GetReplicaX().Get(&version, sqlVersion)
if err != nil {
return "", err
}
@@ -459,7 +460,7 @@ func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
}
func (ss *SqlStore) TotalMasterDbConnections() int {
return ss.GetMaster().Db.Stats().OpenConnections
return ss.GetMasterX().Stats().OpenConnections
}
// ReplicaLagAbs queries all the replica databases to get the absolute replica lag value

Просмотреть файл

@@ -2074,8 +2074,8 @@ func (us SqlUserStore) GetUsersWithInvalidEmails(page int, perPage int, restrict
return nil, errors.Wrap(err, "users_get_many_tosql")
}
var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
users := []*model.User{}
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
return nil, errors.Wrap(err, "users_get_many_select")
}