[MM-61766] Fix errcheck issues in server/channels/app/platform/link_cache.go (#29363)
Этот коммит содержится в:
@@ -100,7 +100,6 @@ issues:
|
|||||||
channels/app/permissions_test.go|\
|
channels/app/permissions_test.go|\
|
||||||
channels/app/platform/helper_test.go|\
|
channels/app/platform/helper_test.go|\
|
||||||
channels/app/platform/license.go|\
|
channels/app/platform/license.go|\
|
||||||
channels/app/platform/link_cache.go|\
|
|
||||||
channels/app/platform/log.go|\
|
channels/app/platform/log.go|\
|
||||||
channels/app/platform/metrics.go|\
|
channels/app/platform/metrics.go|\
|
||||||
channels/app/platform/searchengine.go|\
|
channels/app/platform/searchengine.go|\
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ var linkCache = cache.NewLRU(&cache.CacheOptions{
|
|||||||
Size: LinkCacheSize,
|
Size: LinkCacheSize,
|
||||||
})
|
})
|
||||||
|
|
||||||
func PurgeLinkCache() {
|
func PurgeLinkCache() error {
|
||||||
linkCache.Purge()
|
return linkCache.Purge()
|
||||||
}
|
}
|
||||||
|
|
||||||
func LinkCache() cache.Cache {
|
func LinkCache() cache.Cache {
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ func (s *Server) initPostMetadata() {
|
|||||||
(before.ImageProxySettings.ImageProxyType != after.ImageProxySettings.ImageProxyType) ||
|
(before.ImageProxySettings.ImageProxyType != after.ImageProxySettings.ImageProxyType) ||
|
||||||
(before.ImageProxySettings.RemoteImageProxyURL != after.ImageProxySettings.RemoteImageProxyURL) ||
|
(before.ImageProxySettings.RemoteImageProxyURL != after.ImageProxySettings.RemoteImageProxyURL) ||
|
||||||
(before.ImageProxySettings.RemoteImageProxyOptions != after.ImageProxySettings.RemoteImageProxyOptions) {
|
(before.ImageProxySettings.RemoteImageProxyOptions != after.ImageProxySettings.RemoteImageProxyOptions) {
|
||||||
platform.PurgeLinkCache()
|
if err := platform.PurgeLinkCache(); err != nil {
|
||||||
|
mlog.Warn("Failed to remove cached links when the proxy settings changed", mlog.Err(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2043,7 +2043,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||||
})
|
})
|
||||||
|
|
||||||
platform.PurgeLinkCache()
|
err := platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
return th
|
return th
|
||||||
}
|
}
|
||||||
@@ -2195,7 +2196,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
th.App.saveLinkMetadataToDatabase(requestURL, timestamp, &opengraph.OpenGraph{Title: title}, nil)
|
th.App.saveLinkMetadataToDatabase(requestURL, timestamp, &opengraph.OpenGraph{Title: title}, nil)
|
||||||
|
|
||||||
t.Run("should use database if saved entry exists", func(t *testing.T) {
|
t.Run("should use database if saved entry exists", func(t *testing.T) {
|
||||||
platform.PurgeLinkCache()
|
err := platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
|
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
|
||||||
require.False(t, ok, "data should not exist in in-memory cache")
|
require.False(t, ok, "data should not exist in in-memory cache")
|
||||||
@@ -2212,7 +2214,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should use database if saved entry exists near time", func(t *testing.T) {
|
t.Run("should use database if saved entry exists near time", func(t *testing.T) {
|
||||||
platform.PurgeLinkCache()
|
err := platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
|
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
|
||||||
require.False(t, ok, "data should not exist in in-memory cache")
|
require.False(t, ok, "data should not exist in in-memory cache")
|
||||||
@@ -2229,7 +2232,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should not use database if URL is different", func(t *testing.T) {
|
t.Run("should not use database if URL is different", func(t *testing.T) {
|
||||||
platform.PurgeLinkCache()
|
err := platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
differentURL := requestURL + "/other"
|
differentURL := requestURL + "/other"
|
||||||
|
|
||||||
@@ -2247,7 +2251,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should not use database if timestamp is different", func(t *testing.T) {
|
t.Run("should not use database if timestamp is different", func(t *testing.T) {
|
||||||
platform.PurgeLinkCache()
|
err := platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
differentTimestamp := timestamp + 60*60*1000
|
differentTimestamp := timestamp + 60*60*1000
|
||||||
|
|
||||||
@@ -2455,7 +2460,8 @@ func TestGetLinkMetadata(t *testing.T) {
|
|||||||
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
|
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
|
||||||
require.True(t, ok, "data should now exist in in-memory cache")
|
require.True(t, ok, "data should now exist in in-memory cache")
|
||||||
|
|
||||||
platform.PurgeLinkCache()
|
err = platform.PurgeLinkCache()
|
||||||
|
require.NoError(t, err)
|
||||||
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
|
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
|
||||||
require.False(t, ok, "data should no longer exist in in-memory cache")
|
require.False(t, ok, "data should no longer exist in in-memory cache")
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user