* Fix #10975. AnalyticsUserCountsWithPostsByDay is sync now * revert modifications to go.mod and go.sum * removed unnecessary else sentence * Querys identation
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
969c032a1e
Коммит
28cf642ccb
@@ -171,11 +171,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
r := <-a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
return r.Data.(model.AnalyticsRows), nil
|
||||
return a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
} else if name == "extra_counts" {
|
||||
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
|
||||
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
|
||||
|
||||
@@ -952,12 +952,28 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT DISTINCT
|
||||
DATE(FROM_UNIXTIME(Posts.CreateAt / 1000)) AS Name,
|
||||
COUNT(DISTINCT Posts.UserId) AS Value
|
||||
func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||
query :=
|
||||
`SELECT DISTINCT
|
||||
DATE(FROM_UNIXTIME(Posts.CreateAt / 1000)) AS Name,
|
||||
COUNT(DISTINCT Posts.UserId) AS Value
|
||||
FROM Posts`
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " INNER JOIN Channels ON Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId AND"
|
||||
} else {
|
||||
query += " WHERE"
|
||||
}
|
||||
|
||||
query += ` Posts.CreateAt >= :StartTime AND Posts.CreateAt <= :EndTime
|
||||
GROUP BY DATE(FROM_UNIXTIME(Posts.CreateAt / 1000))
|
||||
ORDER BY Name DESC
|
||||
LIMIT 30`
|
||||
|
||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
query =
|
||||
`SELECT
|
||||
TO_CHAR(DATE(TO_TIMESTAMP(Posts.CreateAt / 1000)), 'YYYY-MM-DD') AS Name, COUNT(DISTINCT Posts.UserId) AS Value
|
||||
FROM Posts`
|
||||
|
||||
if len(teamId) > 0 {
|
||||
@@ -967,42 +983,23 @@ func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.St
|
||||
}
|
||||
|
||||
query += ` Posts.CreateAt >= :StartTime AND Posts.CreateAt <= :EndTime
|
||||
GROUP BY DATE(FROM_UNIXTIME(Posts.CreateAt / 1000))
|
||||
GROUP BY DATE(TO_TIMESTAMP(Posts.CreateAt / 1000))
|
||||
ORDER BY Name DESC
|
||||
LIMIT 30`
|
||||
}
|
||||
|
||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
query =
|
||||
`SELECT
|
||||
TO_CHAR(DATE(TO_TIMESTAMP(Posts.CreateAt / 1000)), 'YYYY-MM-DD') AS Name, COUNT(DISTINCT Posts.UserId) AS Value
|
||||
FROM Posts`
|
||||
end := utils.MillisFromTime(utils.EndOfDay(utils.Yesterday()))
|
||||
start := utils.MillisFromTime(utils.StartOfDay(utils.Yesterday().AddDate(0, 0, -31)))
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " INNER JOIN Channels ON Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId AND"
|
||||
} else {
|
||||
query += " WHERE"
|
||||
}
|
||||
|
||||
query += ` Posts.CreateAt >= :StartTime AND Posts.CreateAt <= :EndTime
|
||||
GROUP BY DATE(TO_TIMESTAMP(Posts.CreateAt / 1000))
|
||||
ORDER BY Name DESC
|
||||
LIMIT 30`
|
||||
}
|
||||
|
||||
end := utils.MillisFromTime(utils.EndOfDay(utils.Yesterday()))
|
||||
start := utils.MillisFromTime(utils.StartOfDay(utils.Yesterday().AddDate(0, 0, -31)))
|
||||
|
||||
var rows model.AnalyticsRows
|
||||
_, err := s.GetReplica().Select(
|
||||
&rows,
|
||||
query,
|
||||
map[string]interface{}{"TeamId": teamId, "StartTime": start, "EndTime": end})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "store.sql_post.analytics_user_counts_posts_by_day.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = rows
|
||||
}
|
||||
})
|
||||
var rows model.AnalyticsRows
|
||||
_, err := s.GetReplica().Select(
|
||||
&rows,
|
||||
query,
|
||||
map[string]interface{}{"TeamId": teamId, "StartTime": start, "EndTime": end})
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "store.sql_post.analytics_user_counts_posts_by_day.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) AnalyticsPostCountsByDay(teamId string) store.StoreChannel {
|
||||
|
||||
@@ -226,7 +226,7 @@ type PostStore interface {
|
||||
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
|
||||
GetEtag(channelId string, allowFromCache bool) string
|
||||
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
||||
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
|
||||
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
||||
AnalyticsPostCountsByDay(teamId string) StoreChannel
|
||||
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
|
||||
ClearCaches()
|
||||
|
||||
@@ -46,19 +46,28 @@ func (_m *PostStore) AnalyticsPostCountsByDay(teamId string) store.StoreChannel
|
||||
}
|
||||
|
||||
// AnalyticsUserCountsWithPostsByDay provides a mock function with given fields: teamId
|
||||
func (_m *PostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.StoreChannel {
|
||||
func (_m *PostStore) AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 model.AnalyticsRows
|
||||
if rf, ok := ret.Get(0).(func(string) model.AnalyticsRows); ok {
|
||||
r0 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(model.AnalyticsRows)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ClearCaches provides a mock function with given fields:
|
||||
|
||||
@@ -1226,15 +1226,15 @@ func testUserCountsWithPostsByDay(t *testing.T, ss store.Store) {
|
||||
o2a.Message = "zz" + model.NewId() + "b"
|
||||
_ = store.Must(ss.Post().Save(o2a)).(*model.Post)
|
||||
|
||||
if r1 := <-ss.Post().AnalyticsUserCountsWithPostsByDay(t1.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Post().AnalyticsUserCountsWithPostsByDay(t1.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
row1 := r1.Data.(model.AnalyticsRows)[0]
|
||||
row1 := r1[0]
|
||||
if row1.Value != 2 {
|
||||
t.Fatal("wrong value")
|
||||
}
|
||||
|
||||
row2 := r1.Data.(model.AnalyticsRows)[1]
|
||||
row2 := r1[1]
|
||||
if row2.Value != 1 {
|
||||
t.Fatal("wrong value")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user