Skip to content

Commit

Permalink
fix sql
Browse files Browse the repository at this point in the history
  • Loading branch information
5rahim committed Aug 13, 2024
1 parent 51d11f4 commit 7851bd2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/database/db/torrentstream_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ func (db *Database) TrimTorrentstreamHistory() {
var count int64
err := db.gormdb.Model(&models.TorrentstreamHistory{}).Count(&count).Error
if err != nil {
db.Logger.Error().Err(err).Msg("database: Failed to count local file entries")
db.Logger.Error().Err(err).Msg("database: Failed to count torrent stream history entries")
return
}
if count > 10 {
// Leave 5 entries
err = db.gormdb.Delete(&models.TorrentstreamHistory{}, "id IN (SELECT id FROM local_files ORDER BY id ASC LIMIT ?)", count-5).Error
err = db.gormdb.Delete(&models.TorrentstreamHistory{}, "id IN (SELECT id FROM torrentstream_histories ORDER BY id ASC LIMIT ?)", count-5).Error
if err != nil {
db.Logger.Error().Err(err).Msg("database: Failed to delete old local file entries")
db.Logger.Error().Err(err).Msg("database: Failed to delete old torrent stream history entries")
return
}
}
Expand Down

0 comments on commit 7851bd2

Please sign in to comment.