Future fetchEarlierCommits()

in results_feed/lib/src/components/app_component.dart [131:159]


  Future<IntRange> fetchEarlierCommits(int before) async {
    final fetchAmount = filterService.filter.singleTest == null
        ? commitFetchSize
        : commitFetchSizeSingleText;
    final newCommits =
        (await _firestoreService.fetchCommits(before, fetchAmount))
            .map((x) => Commit.fromDocument(x));
    if (newCommits.isEmpty) {
      throw Exception('Failed to fetch more commits');
    }
    for (final commit in newCommits) {
      commits[commit.index] = commit;
      final range = IntRange(commit.index, commit.index);
      changeGroups.putIfAbsent(range,
          () => ChangeGroup(range, commits, [], [], LoadedResultsStatus()));
    }
    final range = IntRange(
        commits.keys.last, before == null ? commits.keys.first : before - 1);
    // Add new commits to previously loaded blamelists that included them.
    for (final changeGroup in changeGroups.values) {
      if (changeGroup.range.contains(range.end) &&
          changeGroup.range.length > changeGroup.commits.length) {
        changeGroup.commits = commits.values
            .where((commit) => changeGroup.range.contains(commit.index))
            .toList();
      }
    }
    return range;
  }