mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 08:44:04 +01:00
Index: Improve limit checks and logging #3227
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -65,6 +65,7 @@ func StartIndexing(router *gin.RouterGroup) {
|
|||||||
lastRun := ind.LastRun()
|
lastRun := ind.LastRun()
|
||||||
indexStart := time.Now()
|
indexStart := time.Now()
|
||||||
found, updated := ind.Start(indOpt)
|
found, updated := ind.Start(indOpt)
|
||||||
|
updateMoments := updated > 0 || lastRun.IsZero()
|
||||||
|
|
||||||
log.Infof("index: updated %s [%s]", english.Plural(updated, "file", "files"), time.Since(indexStart))
|
log.Infof("index: updated %s [%s]", english.Plural(updated, "file", "files"), time.Since(indexStart))
|
||||||
|
|
||||||
@@ -85,10 +86,11 @@ func StartIndexing(router *gin.RouterGroup) {
|
|||||||
return
|
return
|
||||||
} else if len(files) > 0 || len(photos) > 0 {
|
} else if len(files) > 0 || len(photos) > 0 {
|
||||||
event.InfoMsg(i18n.MsgRemovedFilesAndPhotos, len(files), len(photos))
|
event.InfoMsg(i18n.MsgRemovedFilesAndPhotos, len(files), len(photos))
|
||||||
|
updateMoments = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update moments?
|
// Update moments?
|
||||||
if updated > 0 || lastRun.IsZero() {
|
if updateMoments {
|
||||||
event.Publish("index.updating", event.Data{
|
event.Publish("index.updating", event.Data{
|
||||||
"step": "moments",
|
"step": "moments",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -229,11 +229,13 @@ func (ind *Index) Start(o IndexOptions) (found fs.Done, updated int) {
|
|||||||
|
|
||||||
if related.Main == nil {
|
if related.Main == nil {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
found[fileName] = fs.Processed
|
|
||||||
return nil
|
return nil
|
||||||
} else if limitErr, _ := related.Main.ExceedsBytes(o.ByteLimit); limitErr != nil {
|
} else if limitErr, fileSize := related.Main.ExceedsBytes(o.ByteLimit); fileSize == 0 {
|
||||||
found[fileName] = fs.Processed
|
found[fileName] = fs.Found
|
||||||
|
return nil
|
||||||
|
} else if limitErr != nil {
|
||||||
log.Warnf("index: %s", limitErr)
|
log.Warnf("index: %s", limitErr)
|
||||||
|
found[fileName] = fs.Processed
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,12 +244,12 @@ func (ind *Index) Start(o IndexOptions) (found fs.Done, updated int) {
|
|||||||
continue
|
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
|
found[f.FileName()] = fs.Found
|
||||||
continue
|
continue
|
||||||
} else if limitErr, _ := f.ExceedsBytes(o.ByteLimit); limitErr != nil {
|
} else if limitErr != nil {
|
||||||
found[f.FileName()] = fs.Found
|
|
||||||
log.Infof("index: %s", limitErr)
|
log.Infof("index: %s", limitErr)
|
||||||
|
found[f.FileName()] = fs.Processed
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1084,26 +1084,26 @@ func (m *MediaFile) Megapixels() (resolution int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExceedsBytes checks if the file exceeds the specified size limit in bytes.
|
// ExceedsBytes checks if the file exceeds the specified size limit in bytes.
|
||||||
func (m *MediaFile) ExceedsBytes(bytes int64) (err error, actual int64) {
|
func (m *MediaFile) ExceedsBytes(limit int64) (err error, fileSize int64) {
|
||||||
if bytes <= 0 {
|
if fileSize = m.FileSize(); limit <= 0 {
|
||||||
return nil, 0
|
return nil, fileSize
|
||||||
} else if actual = m.FileSize(); actual <= 0 || actual <= bytes {
|
} else if fileSize <= 0 || fileSize <= limit {
|
||||||
return nil, actual
|
return nil, fileSize
|
||||||
} else {
|
} 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.
|
// 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 {
|
if limit <= 0 {
|
||||||
return nil, actual
|
return nil, resolution
|
||||||
} else if !m.IsImage() {
|
} else if !m.IsImage() {
|
||||||
return nil, actual
|
return nil, resolution
|
||||||
} else if actual = m.Megapixels(); actual <= 0 || actual <= limit {
|
} else if resolution = m.Megapixels(); resolution <= 0 || resolution <= limit {
|
||||||
return nil, actual
|
return nil, resolution
|
||||||
} else {
|
} 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user