batch_query.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/passport-game-data/model"
  5. "go-common/library/log"
  6. )
  7. func (s *Service) batchQueryLocalNonMiss(c context.Context, mids []int64, batchSize, batchMissRetryCount int) (res []*model.OriginAsoAccount) {
  8. as, miss := s.batchQueryLocalByMid(c, mids, batchSize)
  9. if len(miss) == 0 {
  10. return as
  11. }
  12. res = as
  13. for i := 0; i < batchMissRetryCount; i++ {
  14. log.Info("try for the %dth retry, miss mids: %v", miss)
  15. as, miss = s.batchQueryLocalByMid(c, miss, batchSize)
  16. res = append(res, as...)
  17. if len(miss) == 0 {
  18. return
  19. }
  20. if i == batchMissRetryCount-1 {
  21. log.Error("still miss those mids: %v after %d tries", miss, batchMissRetryCount)
  22. }
  23. }
  24. return
  25. }
  26. func (s *Service) batchQueryLocalByMid(c context.Context, mids []int64, batchSize int) (res []*model.OriginAsoAccount, miss []int64) {
  27. if len(mids) == 0 {
  28. return
  29. }
  30. res = make([]*model.OriginAsoAccount, 0)
  31. miss = make([]int64, 0)
  32. bc := len(mids)/batchSize + 1
  33. for i := 0; i < bc; i++ {
  34. start := i * batchSize
  35. end := (i + 1) * batchSize
  36. if end > len(mids) {
  37. end = len(mids)
  38. }
  39. partMids := mids[start:end]
  40. as, err := s.d.AsoAccountsLocal(c, partMids)
  41. if err != nil {
  42. miss = append(miss, partMids...)
  43. continue
  44. }
  45. res = append(res, as...)
  46. }
  47. return
  48. }
  49. func (s *Service) batchQueryCloudNonMiss(c context.Context, mids []int64, batchSize, batchMissRetryCount int) (res []*model.AsoAccount) {
  50. if len(mids) == 0 {
  51. return
  52. }
  53. as, miss := s.batchQueryCloudByMid(c, mids, batchSize)
  54. if len(miss) == 0 {
  55. return as
  56. }
  57. res = as
  58. for i := 0; i < batchMissRetryCount; i++ {
  59. log.Info("try for the %dth times, miss mids: %v", i, miss)
  60. as, miss = s.batchQueryCloudByMid(c, miss, batchSize)
  61. res = append(res, as...)
  62. if len(miss) == 0 {
  63. return
  64. }
  65. if i == batchMissRetryCount-1 {
  66. log.Error("still miss those mids: %v after %d tries", miss, batchMissRetryCount)
  67. }
  68. }
  69. return
  70. }
  71. func (s *Service) batchQueryCloudByMid(c context.Context, mids []int64, batchSize int) (res []*model.AsoAccount, miss []int64) {
  72. if len(mids) == 0 {
  73. return
  74. }
  75. res = make([]*model.AsoAccount, 0)
  76. miss = make([]int64, 0)
  77. bc := len(mids)/batchSize + 1
  78. for i := 0; i < bc; i++ {
  79. start := i * batchSize
  80. end := (i + 1) * batchSize
  81. if end > len(mids) {
  82. end = len(mids)
  83. }
  84. partMids := mids[start:end]
  85. as, err := s.d.AsoAccountsCloud(c, partMids)
  86. if err != nil {
  87. miss = append(miss, partMids...)
  88. continue
  89. }
  90. res = append(res, as...)
  91. }
  92. return
  93. }