@Override public Collection<EsQueueDto> prepareForRecovery(DbSession dbSession, Collection<String> projectUuids, ProjectIndexer.Cause cause) { switch (cause) { case PROJECT_CREATION: // nothing to do, issues do not exist at project creation case MEASURE_CHANGE: case PROJECT_KEY_UPDATE: case PROJECT_TAGS_UPDATE: case PERMISSION_CHANGE: // nothing to do. Measures, permissions, project key and tags are not used in type issues/issue return emptyList(); case PROJECT_DELETION: List<EsQueueDto> items = projectUuids.stream() .map(projectUuid -> createQueueDto(projectUuid, ID_TYPE_PROJECT_UUID, projectUuid)) .collect(MoreCollectors.toArrayList(projectUuids.size())); return dbClient.esQueueDao().insert(dbSession, items); default: // defensive case throw new IllegalStateException("Unsupported cause: " + cause); } }
/** * Commits the DB transaction and adds the issues to Elasticsearch index. * <p> * If indexing fails, then the recovery daemon will retry later and this * method successfully returns. Meanwhile these issues will be "eventually * consistent" when requesting the index. */ public void commitAndIndexIssues(DbSession dbSession, Collection<IssueDto> issues) { ListMultimap<String, EsQueueDto> itemsByIssueKey = ArrayListMultimap.create(); issues.stream() .map(issue -> createQueueDto(issue.getKey(), ID_TYPE_ISSUE_KEY, issue.getProjectUuid())) // a mutable ListMultimap is needed for doIndexIssueItems, so MoreCollectors.index() is // not used .forEach(i -> itemsByIssueKey.put(i.getDocId(), i)); dbClient.esQueueDao().insert(dbSession, itemsByIssueKey.values()); dbSession.commit(); doIndexIssueItems(dbSession, itemsByIssueKey); }
@Override public Collection<EsQueueDto> prepareForRecovery(DbSession dbSession, Collection<String> projectUuids, ProjectIndexer.Cause cause) { switch (cause) { case PROJECT_CREATION: // nothing to do, issues do not exist at project creation case MEASURE_CHANGE: case PROJECT_KEY_UPDATE: case PROJECT_TAGS_UPDATE: case PERMISSION_CHANGE: // nothing to do. Measures, permissions, project key and tags are not used in type issues/issue return emptyList(); case PROJECT_DELETION: List<EsQueueDto> items = projectUuids.stream() .map(projectUuid -> createQueueDto(projectUuid, ID_TYPE_PROJECT_UUID, projectUuid)) .collect(MoreCollectors.toArrayList(projectUuids.size())); return dbClient.esQueueDao().insert(dbSession, items); default: // defensive case throw new IllegalStateException("Unsupported cause: " + cause); } }
/** * Commits the DB transaction and adds the issues to Elasticsearch index. * <p> * If indexing fails, then the recovery daemon will retry later and this * method successfully returns. Meanwhile these issues will be "eventually * consistent" when requesting the index. */ public void commitAndIndexIssues(DbSession dbSession, Collection<IssueDto> issues) { ListMultimap<String, EsQueueDto> itemsByIssueKey = ArrayListMultimap.create(); issues.stream() .map(issue -> createQueueDto(issue.getKey(), ID_TYPE_ISSUE_KEY, issue.getProjectUuid())) // a mutable ListMultimap is needed for doIndexIssueItems, so MoreCollectors.index() is // not used .forEach(i -> itemsByIssueKey.put(i.getDocId(), i)); dbClient.esQueueDao().insert(dbSession, itemsByIssueKey.values()); dbSession.commit(); doIndexIssueItems(dbSession, itemsByIssueKey); }