Cleanup + debounce scanner notifications

This commit is contained in:
viktorstrate
2020-03-12 12:55:53 +01:00
parent 179ec5283b
commit bdec205031
6 changed files with 19 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ go 1.13
require (
github.com/99designs/gqlgen v0.10.2
github.com/bep/debounce v1.2.0
github.com/disintegration/imaging v1.6.2
github.com/fatih/color v1.9.0
github.com/go-sql-driver/mysql v1.5.0

View File

@@ -3,6 +3,8 @@ github.com/99designs/gqlgen v0.10.2/go.mod h1:aDB7oabSAyZ4kUHLEySsLxnWrBy3lA0A2g
github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/bep/debounce v1.2.0 h1:wXds8Kq8qRfwAOpAxHrJDbCXgC5aHSzgQb/0gKsHQqo=
github.com/bep/debounce v1.2.0/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@@ -10,7 +10,9 @@ import (
"path"
"strconv"
"strings"
"time"
"github.com/bep/debounce"
"github.com/h2non/filetype"
"github.com/viktorstrate/photoview/api/graphql/models"
"github.com/viktorstrate/photoview/api/graphql/notification"
@@ -80,6 +82,7 @@ func scan(database *sql.DB, user *models.User) {
notifyKey := utils.GenerateToken()
processKey := utils.GenerateToken()
scanNotifyDebounce := debounce.New(1 * time.Second)
timeout := 3000
notification.BroadcastNotification(&models.Notification{
@@ -178,14 +181,14 @@ func scan(database *sql.DB, user *models.User) {
if isNewPhoto {
newPhotos.PushBack(photo)
if newPhotos.Len()%25 == 0 {
scanNotifyDebounce(func() {
notification.BroadcastNotification(&models.Notification{
Key: processKey,
Type: models.NotificationTypeMessage,
Header: "Scanning photo",
Content: fmt.Sprintf("Scanning image at %s", photoPath),
})
}
})
}
tx.Commit()
@@ -329,6 +332,7 @@ func isPathImage(path string, cache *scanner_cache) bool {
func processUnprocessedPhotos(database *sql.DB, user *models.User, notifyKey string) error {
processKey := utils.GenerateToken()
processNotifyDebounce := debounce.New(500 * time.Microsecond)
rows, err := database.Query(`
SELECT photo.* FROM photo JOIN album ON photo.album_id = album.album_id
@@ -362,14 +366,16 @@ func processUnprocessedPhotos(database *sql.DB, user *models.User, notifyKey str
continue
}
var progress float64 = float64(count) / float64(len(photosToProcess)) * 100.0
processNotifyDebounce(func() {
var progress float64 = float64(count) / float64(len(photosToProcess)) * 100.0
notification.BroadcastNotification(&models.Notification{
Key: processKey,
Type: models.NotificationTypeProgress,
Header: fmt.Sprintf("Processing photos (%d of %d)", count, len(photosToProcess)),
Content: fmt.Sprintf("Processing photo at %s", photo.Path),
Progress: &progress,
notification.BroadcastNotification(&models.Notification{
Key: processKey,
Type: models.NotificationTypeProgress,
Header: fmt.Sprintf("Processing photos (%d of %d)", count, len(photosToProcess)),
Content: fmt.Sprintf("Processing photo at %s", photo.Path),
Progress: &progress,
})
})
err = ProcessPhoto(tx, photo)

View File

@@ -342,8 +342,6 @@ func (img *ProcessImageData) PhotoImage(tx *sql.Tx) (image.Image, error) {
}
}
log.Printf("ORIENTATION: %d\n", orientation)
switch orientation {
case 2:
photoImg = imaging.FlipH(photoImg)

View File

@@ -7,7 +7,7 @@ import ProtectedImage from './ProtectedImage'
const PhotoContainer = styled.div`
flex-grow: 1;
/* flex-basis: 1; */
flex-basis: 0;
height: 200px;
margin: 4px;
background-color: #eee;

View File

@@ -78,8 +78,6 @@ const PhotoGallery = ({
)
}
console.log(minWidth)
return (
<Photo
key={photo.id}