* MM-43956: Adds post counts by day. * MM-43956: Test data cleanup. Switch from Unix to UnixMilli. * MM-43956: Changes from selecting date data types to strings in SQL. * MM-43956: Fixes date format key. * MM-43956: Adds missing user id scope for 'my' top channels graph. * MM-43956: Adds the ability to group post counts by hour. * MM-43956: Require enterprise or professional license. Reject guests. * MM-43956: Adds license for tests. * MM-43956: Renames function. * MM-43956: Omits future hours from post counts by hour. * MM-43956: Adjust API response grouping to users timezone. * MM-43956: Adds translation. * MM-43956: Adds user's timezone to the data tier for the grouping by day and hour. * MM-43956: Fixes layers. * MM-43956: Lint fix. * MM-43956: Fix store layers. * MM-43956: Switches to default name for time package; changes parameter names to avoid naming conflict. * MM-43956: Updates mocks. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
104 строки
3.3 KiB
Cheetah
104 строки
3.3 KiB
Cheetah
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
// Code generated by "make store-layers"
|
|
// DO NOT EDIT
|
|
|
|
package retrylayer
|
|
|
|
import (
|
|
"context"
|
|
timepkg "time"
|
|
"time"
|
|
|
|
"github.com/lib/pq"
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
"github.com/mattermost/mattermost-server/v6/store"
|
|
"github.com/pkg/errors"
|
|
"github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
const mySQLDeadlockCode = uint16(1213)
|
|
|
|
type {{.Name}} struct {
|
|
store.Store
|
|
{{range $index, $element := .SubStores}} {{$index}}Store store.{{$index}}Store
|
|
{{end}}
|
|
}
|
|
|
|
{{range $index, $element := .SubStores}}func (s *{{$.Name}}) {{$index}}() store.{{$index}}Store {
|
|
return s.{{$index}}Store
|
|
}
|
|
|
|
{{end}}
|
|
|
|
{{range $index, $element := .SubStores}}type {{$.Name}}{{$index}}Store struct {
|
|
store.{{$index}}Store
|
|
Root *{{$.Name}}
|
|
}
|
|
|
|
{{end}}
|
|
|
|
func isRepeatableError(err error) bool {
|
|
var pqErr *pq.Error
|
|
var mysqlErr *mysql.MySQLError
|
|
switch {
|
|
case errors.As(errors.Cause(err), &pqErr):
|
|
if pqErr.Code == "40001" || pqErr.Code == "40P01" {
|
|
return true
|
|
}
|
|
case errors.As(errors.Cause(err), &mysqlErr):
|
|
if mysqlErr.Number == mySQLDeadlockCode {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
{{range $substoreName, $substore := .SubStores}}
|
|
{{range $index, $element := $substore.Methods}}
|
|
func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinParamsWithTypeOutsideStore}}) {{$element.Results | joinResultsForSignature}} {
|
|
{{if $element.Results | len | eq 0}}
|
|
s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
|
{{else}}
|
|
{{if $element.Results | errorPresent}}
|
|
tries := 0
|
|
for {
|
|
{{genResultsVars $element.Results false }} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
|
if {{$element.Results | errorVar}} == nil {
|
|
return {{genResultsVars $element.Results true }}
|
|
}
|
|
if !isRepeatableError({{$element.Results | errorVar}}) {
|
|
return {{genResultsVars $element.Results false }}
|
|
}
|
|
tries++
|
|
if tries >= 3 {
|
|
{{$element.Results | errorVar}} = errors.Wrap({{$element.Results | errorVar}}, "giving up after 3 consecutive repeatable transaction failures")
|
|
return {{genResultsVars $element.Results false }}
|
|
}
|
|
timepkg.Sleep(100 * timepkg.Millisecond)
|
|
}
|
|
{{else}}
|
|
return s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
|
{{end}}
|
|
{{end}}
|
|
}
|
|
{{end}}
|
|
{{end}}
|
|
|
|
{{range $index, $element := .Methods}}
|
|
func (s *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithTypeOutsideStore}}) {{$element.Results | joinResultsForSignature}} {
|
|
{{if $element.Results | len | eq 0}}s.Store.{{$index}}({{$element.Params | joinParams}})
|
|
{{else}}return s.Store.{{$index}}({{$element.Params | joinParams}})
|
|
{{end}}}
|
|
{{end}}
|
|
|
|
func New(childStore store.Store) *{{.Name}} {
|
|
newStore := {{.Name}}{
|
|
Store: childStore,
|
|
}
|
|
{{range $substoreName, $substore := .SubStores}}
|
|
newStore.{{$substoreName}}Store = &{{$.Name}}{{$substoreName}}Store{{"{"}}{{$substoreName}}Store: childStore.{{$substoreName}}(), Root: &newStore}{{end}}
|
|
return &newStore
|
|
}
|