refactor: more SQL logs

This commit is contained in:
Deluan 2020-01-31 17:57:06 -05:00 committed by Deluan Quintão
parent cdbbb2f596
commit 0b91d8a30e
2 changed files with 14 additions and 8 deletions

View File

@ -130,20 +130,20 @@ func (r *albumRepository) Refresh(ids ...string) error {
}
}
if toInsert > 0 {
log.Debug(r.ctx, "Inserted new albums", "num", toInsert)
log.Debug(r.ctx, "Inserted new albums", "totalInserted", toInsert)
}
if toUpdate > 0 {
log.Debug(r.ctx, "Updated albums", "num", toUpdate)
log.Debug(r.ctx, "Updated albums", "totalUpdated", toUpdate)
}
return err
}
func (r *albumRepository) PurgeEmpty() error {
rs, err := r.ormer.Raw("delete from album where id not in (select distinct(album_id) from media_file)").Exec()
del := Delete(r.tableName).Where("id not in (select distinct(album_id) from media_file)")
c, err := r.executeSQL(del)
if err == nil {
c, _ := rs.RowsAffected()
if c > 0 {
log.Debug(r.ctx, "Purged empty albums", "num", c)
log.Debug(r.ctx, "Purged empty albums", "totalDeleted", c)
}
}
return err

View File

@ -148,10 +148,10 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id
}
}
if toInsert > 0 {
log.Debug(r.ctx, "Inserted new artists", "num", toInsert)
log.Debug(r.ctx, "Inserted new artists", "totalInserted", toInsert)
}
if toUpdate > 0 {
log.Debug(r.ctx, "Updated artists", "num", toUpdate)
log.Debug(r.ctx, "Updated artists", "totalUpdated", toUpdate)
}
return err
}
@ -164,7 +164,13 @@ func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Arti
}
func (r *artistRepository) PurgeEmpty() error {
_, err := r.ormer.Raw("delete from artist where id not in (select distinct(artist_id) from album)").Exec()
del := Delete(r.tableName).Where("id not in (select distinct(artist_id) from album)")
c, err := r.executeSQL(del)
if err == nil {
if c > 0 {
log.Debug(r.ctx, "Purged empty artists", "totalDeleted", c)
}
}
return err
}