Skip to content

Commit

Permalink
refactor: process biggest files first
Browse files Browse the repository at this point in the history
  • Loading branch information
alxarno committed Nov 14, 2024
1 parent 060a957 commit a741816
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/tinytune/tinytune.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func start(config Config) {

slog.Info(
"TinyTune",
slog.String("dir", config.dir),
slog.String("version", Version),
slog.Bool("image-processing", config.imageProcessing),
slog.Bool("video-processing", config.videoProcessing),
Expand Down
2 changes: 1 addition & 1 deletion internal/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p Previewer) Pull(path string) (preview.Data, error) {

if contentType == index.ContentTypeVideo && p.video {
preview, err := VideoPreview(path, p.videoParams)
if err != nil {
if err != nil || preview.Duration == 0 {
return defaultPreview, err
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/index/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log/slog"
"path/filepath"
"slices"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -34,6 +35,18 @@ type FileMeta interface {
Size() int64
}

func compareFileMetaSize(a, b FileMeta) int {
if a.Size() == b.Size() {
return 0
}

if a.Size() < b.Size() {
return 1
}

return -1
}

type indexBuilderParams struct {
preview PreviewGenerator
id IDGenerator
Expand Down Expand Up @@ -136,6 +149,9 @@ func (ib *indexBuilder) loadFiles(ctx context.Context) error {
withSemaphore(sem),
withWaitGroup(waitGroup))

// pass biggest files first
slices.SortStableFunc(ib.params.files, compareFileMetaSize)

for _, file := range ib.params.files {
id, err := ib.filePass(file)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions web/scss/_preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
display: -webkit-box;
padding-left: 1rem;
padding-right: 1rem;
overflow-wrap: anywhere;
}

> .wrap {
Expand Down
7 changes: 7 additions & 0 deletions web/scss/_zoom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
margin-bottom: 2px;
border-radius: 0.25rem !important;
}

.dir-list-item>figcaption {
font-size: 0.8rem;
}
}

.zoom-small{
--wrap-width: 160px;
--wrap-height: 140px;
.dir-list-item>figcaption {
font-size: 0.9rem;
}
}

.zoom-medium{
Expand Down

0 comments on commit a741816

Please sign in to comment.