| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'buildbot_data.dart'; | 7 import 'buildbot_data.dart'; |
| 8 import 'buildbot_structures.dart'; | 8 import 'buildbot_structures.dart'; |
| 9 import 'client.dart'; | 9 import 'client.dart'; |
| 10 import 'util.dart'; | 10 import 'util.dart'; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 buildUri = buildUri.prev(); | 33 buildUri = buildUri.prev(); |
| 34 uris.add(buildUri); | 34 uris.add(buildUri); |
| 35 } | 35 } |
| 36 return readResults(uris); | 36 return readResults(uris); |
| 37 } | 37 } |
| 38 | 38 |
| 39 Future<BuildResult> readResult(BuildUri buildUri) { | 39 Future<BuildResult> readResult(BuildUri buildUri) { |
| 40 return _client.readResult(buildUri); | 40 return _client.readResult(buildUri); |
| 41 } | 41 } |
| 42 | 42 |
| 43 /// Maximum number of [BuildResult]s read concurrently by [readResults]. |
| 44 static const maxParallel = 20; |
| 45 |
| 43 /// Reads the build results of all given uris. | 46 /// Reads the build results of all given uris. |
| 44 /// | 47 /// |
| 45 /// Returns a list of the results. If a uri couldn't be read, then the entry | 48 /// Returns a list of the results. If a uri couldn't be read, then the entry |
| 46 /// in the list is `null`. | 49 /// in the list is `null`. |
| 47 Future<List<BuildResult>> readResults(List<BuildUri> buildUris) async { | 50 Future<List<BuildResult>> readResults(List<BuildUri> buildUris) async { |
| 48 var result = <BuildResult>[]; | 51 var result = <BuildResult>[]; |
| 49 int i = 0; | 52 int i = 0; |
| 50 const maxParallel = 20; | |
| 51 while (i < buildUris.length) { | 53 while (i < buildUris.length) { |
| 52 var end = i + maxParallel; | 54 var end = i + maxParallel; |
| 53 if (end > buildUris.length) end = buildUris.length; | 55 if (end > buildUris.length) end = buildUris.length; |
| 54 var parallelChunk = buildUris.sublist(i, end); | 56 var parallelChunk = buildUris.sublist(i, end); |
| 55 log("Fetching ${end - i} uris in parallel"); | 57 log("Fetching ${end - i} uris in parallel"); |
| 56 result.addAll(await Future.wait(parallelChunk.map((uri) { | 58 result.addAll(await Future.wait(parallelChunk.map((uri) { |
| 57 var result = _client.readResult(uri); | 59 var result = _client.readResult(uri); |
| 58 if (result == null) { | 60 if (result == null) { |
| 59 log("Error while reading $uri"); | 61 log("Error while reading $uri"); |
| 60 } | 62 } |
| 61 return result; | 63 return result; |
| 62 }))); | 64 }))); |
| 63 i = end + 1; | 65 i = end; |
| 64 } | 66 } |
| 65 return result; | 67 return result; |
| 66 } | 68 } |
| 67 | 69 |
| 68 /// Returns uris for the most recent build of all build groups. | 70 /// Returns uris for the most recent build of all build groups. |
| 69 List<BuildUri> get mostRecentUris { | 71 List<BuildUri> get mostRecentUris { |
| 70 List<BuildUri> result = []; | 72 List<BuildUri> result = []; |
| 71 for (BuildGroup group in buildGroups) { | 73 for (BuildGroup group in buildGroups) { |
| 72 result.addAll(group.createUris(mostRecentBuildNumber)); | 74 result.addAll(group.createUris(mostRecentBuildNumber)); |
| 73 } | 75 } |
| 74 return result; | 76 return result; |
| 75 } | 77 } |
| 76 | 78 |
| 77 /// Closes the bot. | 79 /// Closes the bot. |
| 78 void close() => _client.close(); | 80 void close() => _client.close(); |
| 79 } | 81 } |
| OLD | NEW |