Sync: Code clean-up #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
02810ffa94
commit
2f5da21a5b
|
@ -36,7 +36,7 @@ func configAction(ctx *cli.Context) error {
|
|||
fmt.Printf("public %t\n", conf.Public())
|
||||
fmt.Printf("experimental %t\n", conf.Experimental())
|
||||
fmt.Printf("workers %d\n", conf.Workers())
|
||||
fmt.Printf("wakeup-interval %d\n", conf.WakeupInterval() / time.Second)
|
||||
fmt.Printf("wakeup-interval %d\n", conf.WakeupInterval()/time.Second)
|
||||
fmt.Printf("log-level %s\n", conf.LogLevel())
|
||||
fmt.Printf("log-filename %s\n", conf.LogFilename())
|
||||
fmt.Printf("pid-filename %s\n", conf.PIDFilename())
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// FileSyncs returns up to 100 file syncs for a given account id and status.
|
||||
func (q *Query) FileSyncs(accountId uint, status string) (result []entity.FileSync, err error) {
|
||||
func (q *Query) FileSyncs(accountId uint, status string, limit int) (result []entity.FileSync, err error) {
|
||||
s := q.db.Where(&entity.FileSync{})
|
||||
|
||||
if accountId > 0 {
|
||||
|
@ -20,7 +20,10 @@ func (q *Query) FileSyncs(accountId uint, status string) (result []entity.FileSy
|
|||
}
|
||||
|
||||
s = s.Order("remote_name ASC")
|
||||
s = s.Limit(1000).Offset(0)
|
||||
|
||||
if limit > 0 {
|
||||
s = s.Limit(limit).Offset(0)
|
||||
}
|
||||
|
||||
s = s.Preload("File")
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ var services struct {
|
|||
Classify *classify.TensorFlow
|
||||
}
|
||||
|
||||
func SetConfig(c *config.Config) {
|
||||
func SetConfig(c *config.Config) {
|
||||
if c == nil {
|
||||
panic("config is nil")
|
||||
}
|
||||
|
|
|
@ -184,19 +184,23 @@ func (s *Sync) getRemoteFiles(a entity.Account) (complete bool, err error) {
|
|||
|
||||
func (s *Sync) relatedDownloads(a entity.Account) (result Downloads, err error) {
|
||||
result = make(Downloads)
|
||||
maxResults := 1000
|
||||
|
||||
files, err := s.q.FileSyncs(a.ID, entity.FileSyncNew)
|
||||
// Get remote files from database
|
||||
files, err := s.q.FileSyncs(a.ID, entity.FileSyncNew, maxResults)
|
||||
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Group results by directory and base name
|
||||
for i, file := range files {
|
||||
k := fs.AbsBase(file.RemoteName)
|
||||
|
||||
result[k] = append(result[k], file)
|
||||
|
||||
if i > 990 {
|
||||
// Skip last 50 to make sure we see all related files
|
||||
if i > (maxResults - 50) {
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
@ -314,11 +318,11 @@ func (s *Sync) download(a entity.Account) (complete bool, err error) {
|
|||
} else {
|
||||
log.Infof("sync: importing %s and related files", file.RemoteName)
|
||||
importJobs <- photoprism.ImportJob{
|
||||
FileName: mf.FileName(),
|
||||
Related: related,
|
||||
IndexOpt: photoprism.IndexOptionsAll(),
|
||||
FileName: mf.FileName(),
|
||||
Related: related,
|
||||
IndexOpt: photoprism.IndexOptionsAll(),
|
||||
ImportOpt: photoprism.ImportOptionsMove(baseDir),
|
||||
Imp: service.Import(),
|
||||
Imp: service.Import(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
var log = event.Log
|
||||
var stop = make(chan bool, 1)
|
||||
|
||||
// Start runs the service workers every 10 minutes.
|
||||
// Start runs PhotoPrism background workers every wakeup interval.
|
||||
func Start(conf *config.Config) {
|
||||
ticker := time.NewTicker(conf.WakeupInterval())
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user