* Fix #10975. GetEtag is sync now * Revert of modifications to go.mod and go.sum
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
719412c1a0
Коммит
e20d91b00e
@@ -607,7 +607,7 @@ func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsEtag(channelId string) string {
|
func (a *App) GetPostsEtag(channelId string) string {
|
||||||
return (<-a.Srv.Store.Post().GetEtag(channelId, true)).Data.(string)
|
return a.Srv.Store.Post().GetEtag(channelId, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
||||||
|
|||||||
@@ -331,36 +331,35 @@ func (s *SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel {
|
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
if allowFromCache {
|
||||||
if allowFromCache {
|
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok {
|
||||||
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok {
|
if s.metrics != nil {
|
||||||
if s.metrics != nil {
|
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
|
||||||
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
|
|
||||||
}
|
|
||||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, cacheItem.(int64))
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return fmt.Sprintf("%v.%v", model.CurrentVersion, cacheItem.(int64))
|
||||||
} else {
|
} else {
|
||||||
if s.metrics != nil {
|
if s.metrics != nil {
|
||||||
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
|
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
var et etagPosts
|
if s.metrics != nil {
|
||||||
err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId})
|
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
|
||||||
if err != nil {
|
|
||||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
|
||||||
} else {
|
|
||||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, et.UpdateAt)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, et.UpdateAt, LAST_POST_TIME_CACHE_SEC)
|
var et etagPosts
|
||||||
})
|
err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId})
|
||||||
|
var result string
|
||||||
|
if err != nil {
|
||||||
|
result = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||||
|
} else {
|
||||||
|
result = fmt.Sprintf("%v.%v", model.CurrentVersion, et.UpdateAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, et.UpdateAt, LAST_POST_TIME_CACHE_SEC)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) *model.AppError {
|
func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) *model.AppError {
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ type PostStore interface {
|
|||||||
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
|
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
|
||||||
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
|
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
|
||||||
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
|
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
|
||||||
GetEtag(channelId string, allowFromCache bool) StoreChannel
|
GetEtag(channelId string, allowFromCache bool) string
|
||||||
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
||||||
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
|
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
|
||||||
AnalyticsPostCountsByDay(teamId string) StoreChannel
|
AnalyticsPostCountsByDay(teamId string) StoreChannel
|
||||||
|
|||||||
@@ -133,16 +133,14 @@ func (_m *PostStore) GetDirectPostParentsForExportAfter(limit int, afterId strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEtag provides a mock function with given fields: channelId, allowFromCache
|
// GetEtag provides a mock function with given fields: channelId, allowFromCache
|
||||||
func (_m *PostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel {
|
func (_m *PostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||||
ret := _m.Called(channelId, allowFromCache)
|
ret := _m.Called(channelId, allowFromCache)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 string
|
||||||
if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, bool) string); ok {
|
||||||
r0 = rf(channelId, allowFromCache)
|
r0 = rf(channelId, allowFromCache)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(string)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ func testPostStoreGet(t *testing.T, ss store.Store) {
|
|||||||
o1.UserId = model.NewId()
|
o1.UserId = model.NewId()
|
||||||
o1.Message = "zz" + model.NewId() + "b"
|
o1.Message = "zz" + model.NewId() + "b"
|
||||||
|
|
||||||
etag1 := (<-ss.Post().GetEtag(o1.ChannelId, false)).Data.(string)
|
etag1 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||||
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
|
|
||||||
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
||||||
|
|
||||||
etag2 := (<-ss.Post().GetEtag(o1.ChannelId, false)).Data.(string)
|
etag2 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||||
if strings.Index(etag2, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
|
if strings.Index(etag2, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
@@ -172,13 +172,13 @@ func testGetEtagCache(t *testing.T, ss store.Store) {
|
|||||||
o1.UserId = model.NewId()
|
o1.UserId = model.NewId()
|
||||||
o1.Message = "zz" + model.NewId() + "b"
|
o1.Message = "zz" + model.NewId() + "b"
|
||||||
|
|
||||||
etag1 := (<-ss.Post().GetEtag(o1.ChannelId, true)).Data.(string)
|
etag1 := ss.Post().GetEtag(o1.ChannelId, true)
|
||||||
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This one should come from the cache
|
// This one should come from the cache
|
||||||
etag2 := (<-ss.Post().GetEtag(o1.ChannelId, true)).Data.(string)
|
etag2 := ss.Post().GetEtag(o1.ChannelId, true)
|
||||||
if strings.Index(etag2, model.CurrentVersion+".") != 0 {
|
if strings.Index(etag2, model.CurrentVersion+".") != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ func testGetEtagCache(t *testing.T, ss store.Store) {
|
|||||||
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
||||||
|
|
||||||
// We have not invalidated the cache so this should be the same as above
|
// We have not invalidated the cache so this should be the same as above
|
||||||
etag3 := (<-ss.Post().GetEtag(o1.ChannelId, true)).Data.(string)
|
etag3 := ss.Post().GetEtag(o1.ChannelId, true)
|
||||||
if strings.Index(etag3, etag2) != 0 {
|
if strings.Index(etag3, etag2) != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ func testGetEtagCache(t *testing.T, ss store.Store) {
|
|||||||
ss.Post().InvalidateLastPostTimeCache(o1.ChannelId)
|
ss.Post().InvalidateLastPostTimeCache(o1.ChannelId)
|
||||||
|
|
||||||
// Invalidated cache so we should get a good result
|
// Invalidated cache so we should get a good result
|
||||||
etag4 := (<-ss.Post().GetEtag(o1.ChannelId, true)).Data.(string)
|
etag4 := ss.Post().GetEtag(o1.ChannelId, true)
|
||||||
if strings.Index(etag4, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
|
if strings.Index(etag4, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
|
|||||||
o1.Message = "zz" + model.NewId() + "b"
|
o1.Message = "zz" + model.NewId() + "b"
|
||||||
deleteByID := model.NewId()
|
deleteByID := model.NewId()
|
||||||
|
|
||||||
etag1 := (<-ss.Post().GetEtag(o1.ChannelId, false)).Data.(string)
|
etag1 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||||
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
@@ -363,7 +363,7 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
etag2 := (<-ss.Post().GetEtag(o1.ChannelId, false)).Data.(string)
|
etag2 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||||
if strings.Index(etag2, model.CurrentVersion+".") != 0 {
|
if strings.Index(etag2, model.CurrentVersion+".") != 0 {
|
||||||
t.Fatal("Invalid Etag")
|
t.Fatal("Invalid Etag")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user