Index: Improve limit checks and logging #3227

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2023-02-23 04:11:09 +01:00
parent 668395909d
commit 5b727dd86a
3 changed files with 23 additions and 19 deletions

View File

@@ -65,6 +65,7 @@ func StartIndexing(router *gin.RouterGroup) {
lastRun := ind.LastRun()
indexStart := time.Now()
found, updated := ind.Start(indOpt)
updateMoments := updated > 0 || lastRun.IsZero()
log.Infof("index: updated %s [%s]", english.Plural(updated, "file", "files"), time.Since(indexStart))
@@ -85,10 +86,11 @@ func StartIndexing(router *gin.RouterGroup) {
return
} else if len(files) > 0 || len(photos) > 0 {
event.InfoMsg(i18n.MsgRemovedFilesAndPhotos, len(files), len(photos))
updateMoments = true
}
// Update moments?
if updated > 0 || lastRun.IsZero() {
if updateMoments {
event.Publish("index.updating", event.Data{
"step": "moments",
})

View File

@@ -229,11 +229,13 @@ func (ind *Index) Start(o IndexOptions) (found fs.Done, updated int) {
if related.Main == nil {
// Nothing to do.
found[fileName] = fs.Processed
return nil
} else if limitErr, _ := related.Main.ExceedsBytes(o.ByteLimit); limitErr != nil {
found[fileName] = fs.Processed
} else if limitErr, fileSize := related.Main.ExceedsBytes(o.ByteLimit); fileSize == 0 {
found[fileName] = fs.Found
return nil
} else if limitErr != nil {
log.Warnf("index: %s", limitErr)
found[fileName] = fs.Processed
return nil
}
@@ -242,12 +244,12 @@ func (ind *Index) Start(o IndexOptions) (found fs.Done, updated int) {
continue
}
if fileSize := f.FileSize(); fileSize == 0 || ind.files.Indexed(f.RootRelName(), f.Root(), f.ModTime(), o.Rescan) {
if limitErr, fileSize := f.ExceedsBytes(o.ByteLimit); fileSize == 0 || ind.files.Indexed(f.RootRelName(), f.Root(), f.ModTime(), o.Rescan) {
found[f.FileName()] = fs.Found
continue
} else if limitErr, _ := f.ExceedsBytes(o.ByteLimit); limitErr != nil {
found[f.FileName()] = fs.Found
} else if limitErr != nil {
log.Infof("index: %s", limitErr)
found[f.FileName()] = fs.Processed
continue
}

View File

@@ -1084,26 +1084,26 @@ func (m *MediaFile) Megapixels() (resolution int) {
}
// ExceedsBytes checks if the file exceeds the specified size limit in bytes.
func (m *MediaFile) ExceedsBytes(bytes int64) (err error, actual int64) {
if bytes <= 0 {
return nil, 0
} else if actual = m.FileSize(); actual <= 0 || actual <= bytes {
return nil, actual
func (m *MediaFile) ExceedsBytes(limit int64) (err error, fileSize int64) {
if fileSize = m.FileSize(); limit <= 0 {
return nil, fileSize
} else if fileSize <= 0 || fileSize <= limit {
return nil, fileSize
} else {
return fmt.Errorf("%s exceeds file size limit (%s / %s)", clean.Log(m.RootRelName()), humanize.Bytes(uint64(actual)), humanize.Bytes(uint64(bytes))), actual
return fmt.Errorf("%s exceeds file size limit (%s / %s)", clean.Log(m.RootRelName()), humanize.Bytes(uint64(fileSize)), humanize.Bytes(uint64(limit))), fileSize
}
}
// ExceedsResolution checks if an image in a natively supported format exceeds the configured resolution limit in megapixels.
func (m *MediaFile) ExceedsResolution(limit int) (err error, actual int) {
func (m *MediaFile) ExceedsResolution(limit int) (err error, resolution int) {
if limit <= 0 {
return nil, actual
return nil, resolution
} else if !m.IsImage() {
return nil, actual
} else if actual = m.Megapixels(); actual <= 0 || actual <= limit {
return nil, actual
return nil, resolution
} else if resolution = m.Megapixels(); resolution <= 0 || resolution <= limit {
return nil, resolution
} else {
return fmt.Errorf("%s exceeds resolution limit (%d / %d MP)", clean.Log(m.RootRelName()), actual, limit), actual
return fmt.Errorf("%s exceeds resolution limit (%d / %d MP)", clean.Log(m.RootRelName()), resolution, limit), resolution
}
}