Skip to content

Commit

Permalink
fix: Fixing too many thumbnail fetch
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Nov 5, 2022
1 parent f281226 commit b38c592
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/fibr/static/scripts/async-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ document.addEventListener(
return;
}

if (typeof fetchThumbnail === 'undefined' || !fetchThumbnail) {
if (typeof hasThumbnail === 'undefined' || !hasThumbnail) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fibr/static/scripts/index.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/fibr/templates/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@

{{ if and (eq .Request.Display "grid") .HasThumbnail }}
<script type="text/javascript" nonce="{{ .nonce }}">
const fetchThumbnail = true;
const hasThumbnail = true;
</script>
{{ end }}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion cmd/fibr/templates/story.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ $root := . }}

<script type="text/javascript" nonce="{{ .nonce }}">
const fetchThumbnail = true;
const hasThumbnail = true;
const lazyLoadThumbnail = true;
</script>

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ViBiOh/auth/v2 v2.14.20
github.com/ViBiOh/exas v0.5.11
github.com/ViBiOh/flags v1.2.0
github.com/ViBiOh/httputils/v4 v4.50.0
github.com/ViBiOh/httputils/v4 v4.50.1
github.com/ViBiOh/vith v0.5.10
github.com/golang/mock v1.6.0
github.com/prometheus/client_golang v1.13.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/ViBiOh/exas v0.5.11 h1:KpW9mmt+Fe3I2l11UXovye8wWZ+zoV8LVVyCcvH6j+w=
github.com/ViBiOh/exas v0.5.11/go.mod h1:A1dbq+ZR5yBo4RkDWhg4M2hze9MLTBUDMk5gRliWEEk=
github.com/ViBiOh/flags v1.2.0 h1:DaujjNXzD29KxKyp4eZdn7c9+uBN5DokWgDAe7DcUmc=
github.com/ViBiOh/flags v1.2.0/go.mod h1:UyMB5zeD/aId7Xw3x7577ZNU298JmukzOcV8p/H2W1s=
github.com/ViBiOh/httputils/v4 v4.50.0 h1:87oPPf4hvE8SetNpUOxxNUazhn8XCESz0glvJcj+KgU=
github.com/ViBiOh/httputils/v4 v4.50.0/go.mod h1:yp/iCcK7SBdQfxCqPNwvF4J8WAVZ3M1o95gfFCJIsbE=
github.com/ViBiOh/httputils/v4 v4.50.1 h1:NHtJvM8Vf05DXAyQ9jgmLMBrjTERagD+bCBBTCvOIGc=
github.com/ViBiOh/httputils/v4 v4.50.1/go.mod h1:yp/iCcK7SBdQfxCqPNwvF4J8WAVZ3M1o95gfFCJIsbE=
github.com/ViBiOh/vith v0.5.10 h1:BriyDGDFmBRpJpbQhsFxIlq2bT9HmuJ/q903Y+0w0S0=
github.com/ViBiOh/vith v0.5.10/go.mod h1:JcGIWVjvXA0zYHz/picn+xMIdk7ljbYjDp7d16BufzM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
118 changes: 118 additions & 0 deletions pkg/mocks/cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/thumbnail/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ViBiOh/vith/pkg/model"
)

//go:generate mockgen -destination ../mocks/cache.go -package mocks -mock_names RedisClient=RedisClient github.com/ViBiOh/httputils/v4/pkg/cache RedisClient

var redisCacheDuration = time.Hour * 96

func (a App) CanHaveThumbnail(item absto.Item) bool {
Expand Down
10 changes: 6 additions & 4 deletions pkg/thumbnail/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ func TestHasThumbnail(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

storageMock := mocks.NewStorage(ctrl)
mockStorage := mocks.NewStorage(ctrl)
mockRedisClient := mocks.NewRedisClient(ctrl)

tc.instance.storageApp = storageMock
tc.instance.cacheApp = cache.New(nil, nil, storageMock.Info, 0, 0, nil)
tc.instance.storageApp = mockStorage
tc.instance.cacheApp = cache.New(mockRedisClient, nil, mockStorage.Info, 0, 0, nil)

if intention == "found" {
storageMock.EXPECT().Info(gomock.Any(), gomock.Any()).Return(absto.Item{}, nil)
mockRedisClient.EXPECT().Enabled().Return(false)
mockStorage.EXPECT().Info(gomock.Any(), gomock.Any()).Return(absto.Item{}, nil)
}

if result := tc.instance.HasThumbnail(context.TODO(), tc.input, SmallSize); result != tc.want {
Expand Down

0 comments on commit b38c592

Please sign in to comment.