protected Set determineLatestBuilds()

in tcbot-teamcity-ignited/src/main/java/org/apache/ignite/tcignited/history/HistoryCollector.java [142:196]


    protected Set<Integer> determineLatestBuilds(
        int srvId, int buildTypeId, int normalizedBaseBranch, Set<Integer> knownBuilds) {
        String btId = compactor.getStringFromId(buildTypeId);
        String branchId = compactor.getStringFromId(normalizedBaseBranch);
        Set<Integer> strings = branchEquivalence.branchIdsForQuery(branchId, compactor);
        List<BuildRefCompacted> bRefsList =
            buildRefDao.getAllBuildsCompacted(srvId, buildTypeId, strings);

        long curTs = System.currentTimeMillis();
        Set<Integer> buildIds = bRefsList.stream()
            .filter(b -> {
                Integer maxBuildIdForDay = buildStartTimeStorage.getBorderForAgeForBuildId(srvId, TcBotConst.HISTORY_BUILD_ID_BORDER_DAYS);

                if (maxBuildIdForDay == null)
                    return true;

                return b.id() > maxBuildIdForDay;

            })
            .filter(this::applicableForHistory)
            .map(BuildRefCompacted::id)
            .filter(bId -> !knownBuilds.contains(bId)).collect(Collectors.toSet());

        logger.info("***** Loading build start time history for suite "
            + compactor.getStringFromId(buildTypeId)
            + " branch " + compactor.getStringFromId(normalizedBaseBranch) + ": " + buildIds.size() + " builds" );

        Map<Integer, Long> buildStartTimes = getStartTimeFromSpecialCache(srvId, buildIds);

        Set<Integer> notFoundKeys = new HashSet<>(buildIds);
        notFoundKeys.removeAll(buildStartTimes.keySet());

        if (!notFoundKeys.isEmpty()) {
            Map<Integer, Long> buildStartTimeFromFatBuild = getStartTimeFromFatBuild(srvId, notFoundKeys);

            buildStartTimes.putAll(buildStartTimeFromFatBuild);

            buildStartTimeStorage.setBuildsStartTime(srvId, buildStartTimeFromFatBuild);
        }

        long minBuildStartTs = curTs - Duration.ofDays(TcBotConst.HISTORY_MAX_DAYS).toMillis();

        Set<Integer> buildInScope = buildIds.stream().filter(
            bId -> {
                Long startTime = buildStartTimes.get(bId);

                return startTime != null && startTime > minBuildStartTs;
            }
        ).collect(Collectors.toSet());

        logger.info("*** Build " + btId + " branch " + branchId + " builds in scope " +
            buildInScope.size() + " from " + bRefsList.size());

        return buildInScope;
    }