@Override public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { try (DbSession dbSession = dbClient.openSession(false)) { ListMultimap<String, String> organizationUuidsByUserUuid = ArrayListMultimap.create(); dbClient.organizationMemberDao().selectAllForUserIndexing(dbSession, organizationUuidsByUserUuid::put); BulkIndexer bulkIndexer = newBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR); bulkIndexer.start(); dbClient.userDao().scrollAll(dbSession, // only index requests, no deletion requests. // Deactivated users are not deleted but updated. u -> bulkIndexer.add(newIndexRequest(u, organizationUuidsByUserUuid))); bulkIndexer.stop(); } }
@Test public void select_all_for_indexing() { OrganizationDto org1 = db.organizations().insert(o -> o.setUuid("ORG_1")); OrganizationDto org2 = db.organizations().insert(o -> o.setUuid("ORG_2")); UserDto user1 = db.users().insertUser(); UserDto user2 = db.users().insertUser(); db.organizations().addMember(org1, user1); db.organizations().addMember(org1, user2); db.organizations().addMember(org2, user1); List<Tuple> result = new ArrayList<>(); underTest.selectAllForUserIndexing(dbSession, (login, org) -> result.add(tuple(login, org))); assertThat(result).containsOnly(tuple(user1.getUuid(), "ORG_1"), tuple(user1.getUuid(), "ORG_2"), tuple(user2.getUuid(), "ORG_1")); }
@Override public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { try (DbSession dbSession = dbClient.openSession(false)) { ListMultimap<String, String> organizationUuidsByUserUuid = ArrayListMultimap.create(); dbClient.organizationMemberDao().selectAllForUserIndexing(dbSession, organizationUuidsByUserUuid::put); BulkIndexer bulkIndexer = newBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR); bulkIndexer.start(); dbClient.userDao().scrollAll(dbSession, // only index requests, no deletion requests. // Deactivated users are not deleted but updated. u -> bulkIndexer.add(newIndexRequest(u, organizationUuidsByUserUuid))); bulkIndexer.stop(); } }