sync.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package upper
  2. import (
  3. "context"
  4. xsql "go-common/library/database/sql"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _toSyncUps = "SELECT mid FROM ugc_uploader WHERE submit = 1 AND deleted = 0"
  9. _finishSyncUps = "UPDATE ugc_uploader SET submit = 0 WHERE mid = ? AND deleted = 0"
  10. )
  11. // TosyncUps gets all the uppers that need to sync ( with archives )
  12. func (d *Dao) TosyncUps(c context.Context) (mids []int64, err error) {
  13. var rows *xsql.Rows
  14. if rows, err = d.DB.Query(c, _toSyncUps); err != nil {
  15. log.Error("d.TosyncUps.Query error(%v)", err)
  16. return
  17. }
  18. defer rows.Close()
  19. for rows.Next() {
  20. var r int64
  21. if err = rows.Scan(&r); err != nil {
  22. log.Error("TosyncUps row.Scan() error(%v)", err)
  23. return
  24. }
  25. mids = append(mids, r)
  26. }
  27. if err = rows.Err(); err != nil {
  28. log.Error("d.ToSyncUps.Query error(%v)", err)
  29. }
  30. return
  31. }
  32. // FinsyncUps is used to update the upper's submit from 1 to 0, after the sync is finished
  33. func (d *Dao) FinsyncUps(c context.Context, mid int64) (err error) {
  34. if _, err = d.DB.Exec(c, _finishSyncUps, mid); err != nil {
  35. log.Error("FinsyncUps Error: %v", mid, err)
  36. }
  37. return
  38. }