|
7 | 7 | "sort" |
8 | 8 | "strconv" |
9 | 9 | "strings" |
10 | | - "sync" |
11 | 10 | "time" |
12 | 11 |
|
13 | 12 | "github.com/NeedleInAJayStack/haystack" |
@@ -205,37 +204,24 @@ func (datasource *Datasource) query(ctx context.Context, pCtx backend.PluginCont |
205 | 204 | return backend.ErrDataResponse(backend.StatusBadRequest, errMsg) |
206 | 205 | } |
207 | 206 |
|
208 | | - // Function to read a single point and send it to a channel. |
209 | | - readPoint := func(point haystack.Row, hisReadChannel chan haystack.Grid, wg *sync.WaitGroup) { |
210 | | - hisRead, err := datasource.hisRead(point, query.TimeRange) |
211 | | - if err != nil { |
212 | | - log.DefaultLogger.Error(err.Error()) |
213 | | - } |
214 | | - hisReadChannel <- hisRead // hisRead is empty under error condition |
215 | | - wg.Done() |
216 | | - } |
217 | | - |
218 | | - // Start a goroutine to collect all the grids into a slice. |
219 | | - hisReadChannel := make(chan haystack.Grid) |
220 | | - combinedChannel := make(chan []haystack.Grid) |
221 | | - go func() { |
222 | | - grids := []haystack.Grid{} |
223 | | - for grid := range hisReadChannel { |
224 | | - grids = append(grids, grid) |
225 | | - } |
226 | | - combinedChannel <- grids |
227 | | - }() |
228 | | - |
229 | 207 | // Read all the points in parallel using goroutines. |
230 | | - var wg sync.WaitGroup |
231 | | - wg.Add(len(points)) |
| 208 | + hisReadChannel := make(chan haystack.Grid) |
232 | 209 | for _, point := range points { |
233 | | - go readPoint(point, hisReadChannel, &wg) |
| 210 | + go func() { |
| 211 | + hisRead, err := datasource.hisRead(point, query.TimeRange) |
| 212 | + if err != nil { |
| 213 | + log.DefaultLogger.Error(err.Error()) |
| 214 | + } |
| 215 | + hisReadChannel <- hisRead // hisRead is empty under error condition |
| 216 | + }() |
| 217 | + } |
| 218 | + |
| 219 | + grids := []haystack.Grid{} |
| 220 | + for _ = range len(points) { |
| 221 | + grid := <-hisReadChannel |
| 222 | + grids = append(grids, grid) |
234 | 223 | } |
235 | | - wg.Wait() |
236 | | - close(hisReadChannel) |
237 | 224 |
|
238 | | - grids := <-combinedChannel |
239 | 225 | response := responseFromGrids(grids) |
240 | 226 | // Make the display name on the "val" fields the names of the points. |
241 | 227 | for _, frame := range response.Frames { |
|
0 commit comments