@@ -111,39 +111,53 @@ func (b *Backend) getTasksByUIDs(queueUID string, taskUIDs []string, filter func
111111 if len (taskUIDs ) == 0 {
112112 return []* task.Task {}, nil
113113 }
114- taskKeys := []string {}
115- for _ , uid := range taskUIDs {
116- taskKeys = append (taskKeys , b .taskKey (queueUID , uid ))
117- }
118- rawTasks , err := b .Client .MGet (taskKeys ... ).Result ()
119- if err != nil {
120- return nil , err
114+
115+ chunks := [][]string {}
116+ chunkSize := b .RedisConfig .ChunkSizeInGet
117+ for i := 0 ; i < len (taskUIDs ); i += chunkSize {
118+ until := len (taskUIDs )
119+ if i + chunkSize <= len (taskUIDs ) {
120+ until = i + chunkSize
121+ }
122+ chunks = append (chunks , taskUIDs [i :until ])
121123 }
124+
122125 tasks := []* task.Task {}
123- for _ , rawTask := range rawTasks {
124- if rawTask == nil {
125- lggr .Error ().
126- Interface ("rawData" , nil ).
127- Msg ("Internal error. rawData is null. Skipped." )
128- continue
126+ for _ , chunk := range chunks {
127+ taskKeys := []string {}
128+ for _ , uid := range chunk {
129+ taskKeys = append (taskKeys , b .taskKey (queueUID , uid ))
129130 }
130- var t task.Task
131- rawTaskStr , ok := rawTask .(string )
132- if ! ok {
133- lggr .Error ().
134- Interface ("rawData" , rawTask ).
135- Str ("type" , reflect .TypeOf (rawTask ).String ()).
136- Msg ("Internal error. rawData should be string. Skipped." )
137- continue
138- }
139- if err := json .Unmarshal ([]byte (rawTaskStr ), & t ); err != nil {
140- lggr .Error ().Str ("data" , rawTaskStr ).Msg ("Failed to unmarshal to Task. Skipped." )
141- continue
131+ rawTasks , err := b .Client .MGet (taskKeys ... ).Result ()
132+ if err != nil {
133+ return nil , err
142134 }
143- if filter (& t ) {
144- tasks = append (tasks , & t )
135+ for _ , rawTask := range rawTasks {
136+ if rawTask == nil {
137+ lggr .Error ().
138+ Interface ("rawData" , nil ).
139+ Msg ("Internal error. rawData is null. Skipped." )
140+ continue
141+ }
142+ var t task.Task
143+ rawTaskStr , ok := rawTask .(string )
144+ if ! ok {
145+ lggr .Error ().
146+ Interface ("rawData" , rawTask ).
147+ Str ("type" , reflect .TypeOf (rawTask ).String ()).
148+ Msg ("Internal error. rawData should be string. Skipped." )
149+ continue
150+ }
151+ if err := json .Unmarshal ([]byte (rawTaskStr ), & t ); err != nil {
152+ lggr .Error ().Str ("data" , rawTaskStr ).Msg ("Failed to unmarshal to Task. Skipped." )
153+ continue
154+ }
155+ if filter (& t ) {
156+ tasks = append (tasks , & t )
157+ }
145158 }
146159 }
160+
147161 return tasks , nil
148162}
149163
0 commit comments