[MM-61766] Fix errcheck issues in server/channels/app/platform/link_cache.go (#29363)

Этот коммит содержится в:
Ivy Gesare
2024-11-25 15:41:16 +03:00
коммит произвёл GitHub
родитель 2d841962b0
Коммит a61ffadd84
4 изменённых файлов: 17 добавлений и 10 удалений

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

@@ -100,7 +100,6 @@ issues:
channels/app/permissions_test.go|\
channels/app/platform/helper_test.go|\
channels/app/platform/license.go|\
channels/app/platform/link_cache.go|\
channels/app/platform/log.go|\
channels/app/platform/metrics.go|\
channels/app/platform/searchengine.go|\

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

@@ -16,8 +16,8 @@ var linkCache = cache.NewLRU(&cache.CacheOptions{
Size: LinkCacheSize,
})
func PurgeLinkCache() {
linkCache.Purge()
func PurgeLinkCache() error {
return linkCache.Purge()
}
func LinkCache() cache.Cache {

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

@@ -46,7 +46,9 @@ func (s *Server) initPostMetadata() {
(before.ImageProxySettings.ImageProxyType != after.ImageProxySettings.ImageProxyType) ||
(before.ImageProxySettings.RemoteImageProxyURL != after.ImageProxySettings.RemoteImageProxyURL) ||
(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"
})
platform.PurgeLinkCache()
err := platform.PurgeLinkCache()
require.NoError(t, err)
return th
}
@@ -2195,7 +2196,8 @@ func TestGetLinkMetadata(t *testing.T) {
th.App.saveLinkMetadataToDatabase(requestURL, timestamp, &opengraph.OpenGraph{Title: title}, nil)
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)
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) {
platform.PurgeLinkCache()
err := platform.PurgeLinkCache()
require.NoError(t, err)
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
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) {
platform.PurgeLinkCache()
err := platform.PurgeLinkCache()
require.NoError(t, err)
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) {
platform.PurgeLinkCache()
err := platform.PurgeLinkCache()
require.NoError(t, err)
differentTimestamp := timestamp + 60*60*1000
@@ -2455,7 +2460,8 @@ func TestGetLinkMetadata(t *testing.T) {
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
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)
require.False(t, ok, "data should no longer exist in in-memory cache")