cont_del.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package app
  2. import (
  3. "context"
  4. dsql "database/sql"
  5. "fmt"
  6. "time"
  7. model "go-common/app/job/main/tv/model/pgc"
  8. "go-common/library/database/sql"
  9. "go-common/library/log"
  10. "go-common/library/xstr"
  11. )
  12. const (
  13. _deletedContSQL = "SELECT id, title, subtitle, `desc`, cover, epid, season_id, cid FROM tv_content WHERE state = ? AND is_deleted = 1 AND audit_time < UNIX_TIMESTAMP(now()) ORDER BY season_id, epid LIMIT 0,"
  14. _delaySyncSQL = "UPDATE tv_content SET audit_time = ? WHERE epid IN (%s)"
  15. _delSyncContSQL = "UPDATE tv_content SET state = ? WHERE is_deleted = 1 AND epid = ?"
  16. )
  17. // DelCont picks the deleted content data to sync
  18. func (d *Dao) DelCont(c context.Context) (res []*model.Content, err error) {
  19. var (
  20. rows *sql.Rows
  21. nbData = d.conf.Sync.LConf.SizeMsg
  22. )
  23. if rows, err = d.DB.Query(c, _deletedContSQL+fmt.Sprintf("%d", nbData), EPToAudit); err != nil {
  24. log.Error("d._deletedEPSQL.Query error(%v)", err)
  25. return
  26. }
  27. defer rows.Close()
  28. for rows.Next() {
  29. var r = &model.Content{}
  30. if err = rows.Scan(&r.ID, &r.Title, &r.Subtitle, &r.Desc, &r.Cover, &r.EPID, &r.SeasonID, &r.CID); err != nil {
  31. log.Error("DelCont row.Scan() error(%v)", err)
  32. return
  33. }
  34. res = append(res, r)
  35. }
  36. if err = rows.Err(); err != nil {
  37. log.Error("d.DelCont.Query error(%v)", err)
  38. }
  39. return
  40. }
  41. // SyncCont updates the delete content's state to not pass, avoid being selected again
  42. func (d *Dao) SyncCont(c context.Context, cid int) (nbRows int64, err error) {
  43. var res dsql.Result
  44. if res, err = d.DB.Exec(c, _delSyncContSQL, EPNotPass, cid); err != nil {
  45. log.Error("_delSyncContSQL, failed to update to auditing: (%v), Error: %v", cid, err)
  46. return
  47. }
  48. return res.RowsAffected()
  49. }
  50. // DelaySync postpones the sync of the deleted content, in case of there is an error happenning in the interface
  51. func (d *Dao) DelaySync(c context.Context, conts []*model.Content) (nbRows int64, err error) {
  52. var (
  53. res dsql.Result
  54. xstrIds []int64
  55. delay = time.Now().Unix() + int64(d.conf.Sync.Frequency.AuditDelay) // postpone the season's eps auditing to when
  56. )
  57. for _, v := range conts {
  58. xstrIds = append(xstrIds, int64(v.EPID))
  59. }
  60. if res, err = d.DB.Exec(c, fmt.Sprintf(_delaySyncSQL, xstr.JoinInts(xstrIds)), delay); err != nil {
  61. log.Error("_delSyncContSQL, failed to delay: (%v,%v), Error: %v", delay, xstrIds, err)
  62. return
  63. }
  64. return res.RowsAffected()
  65. }