Evaluate streams in GroupIncludeCacheImpl while the db is still open
Streams are evaluated lazily. For this reason, we must execute all operations on a stream inside of a try-resources statement. This is an adaption of commit I49681b0d0128a6523e670b6b2a1b4a5ca3c3e932 to the code of 2.15. The second stream of GroupIncludeCacheImpl isn't present in 2.15 as that code is still part of AccountCacheImpl. The implementation in AccountCacheImpl doesn't close the stream too early and hence doesn't need a fix. Change-Id: I42b45ed51c3f9c137b59490814a2b71ea4103eba
This commit is contained in:
parent
860e30632f
commit
90c9c88c56
@ -41,7 +41,6 @@ import com.google.inject.name.Named;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Stream;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -183,18 +182,21 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
|
||||
@Override
|
||||
public ImmutableList<AccountGroup.UUID> load(AccountGroup.UUID key) throws OrmException {
|
||||
Stream<InternalGroup> internalGroupStream;
|
||||
if (groupIndexProvider.get().getSchema().hasField(GroupField.SUBGROUP)) {
|
||||
internalGroupStream = groupQueryProvider.get().bySubgroup(key).stream();
|
||||
} else {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
internalGroupStream =
|
||||
Groups.getParentGroupsFromReviewDb(db, key)
|
||||
.map(groupCache::get)
|
||||
.flatMap(Streams::stream);
|
||||
}
|
||||
return groupQueryProvider
|
||||
.get()
|
||||
.bySubgroup(key)
|
||||
.stream()
|
||||
.map(InternalGroup::getGroupUUID)
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
try (ReviewDb db = schema.open()) {
|
||||
return Groups.getParentGroupsFromReviewDb(db, key)
|
||||
.map(groupCache::get)
|
||||
.flatMap(Streams::stream)
|
||||
.map(InternalGroup::getGroupUUID)
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
return internalGroupStream.map(InternalGroup::getGroupUUID).collect(toImmutableList());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user