archive_history.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "time"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _hisCntSQL = "SELECT COUNT(*) FROM archive_edit_history WHERE aid=?"
  10. _delEditHisSQL = "DELETE FROM archive_edit_history WHERE mtime < ? LIMIT ?"
  11. _delVideoEditHisSQL = "DELETE FROM archive_video_edit_history WHERE mtime < ? LIMIT ?"
  12. )
  13. // HistoryCount get a archive history count.
  14. func (d *Dao) HistoryCount(c context.Context, aid int64) (count int, err error) {
  15. row := d.db.QueryRow(c, _hisCntSQL, aid)
  16. if err = row.Scan(&count); err != nil {
  17. if err == sql.ErrNoRows {
  18. err = nil
  19. } else {
  20. log.Error("row.Scan error(%v)", err)
  21. }
  22. }
  23. return
  24. }
  25. // DelArcEditHistoryBefore delete archive_edit_history before t.
  26. func (d *Dao) DelArcEditHistoryBefore(c context.Context, t time.Time, limit int64) (rows int64, err error) {
  27. res, err := d.db.Exec(c, _delEditHisSQL, t, limit)
  28. if err != nil {
  29. log.Error("db.Exec(%s, %s) error(%v)", _delEditHisSQL, t, err)
  30. return
  31. }
  32. return res.RowsAffected()
  33. }
  34. // DelArcVideoEditHistoryBefore delete archive_video_edit_history before t.
  35. func (d *Dao) DelArcVideoEditHistoryBefore(c context.Context, t time.Time, limit int64) (rows int64, err error) {
  36. res, err := d.db.Exec(c, _delVideoEditHisSQL, t, limit)
  37. if err != nil {
  38. log.Error("db.Exec(%s, %s) error(%v)", _delVideoEditHisSQL, t, err)
  39. return
  40. }
  41. return res.RowsAffected()
  42. }