Commit 7e0871d51b28a329017ca6f4dbde1bf9b1b0a91d
Committed by
GitHub
Merge pull request #571 from dmytro-landiak/master
fix in relations caching
Showing
1 changed file
with
14 additions
and
10 deletions
... | ... | @@ -200,8 +200,10 @@ public class BaseRelationService implements RelationService { |
200 | 200 | private void checkFromDeleteSync(Cache cache, List<Boolean> results, EntityRelation relation, boolean isRemove) { |
201 | 201 | if (isRemove) { |
202 | 202 | results.add(relationDao.deleteRelation(relation)); |
203 | + cacheEviction(relation, relation.getTo(), cache); | |
204 | + } else { | |
205 | + cacheEviction(relation, relation.getFrom(), cache); | |
203 | 206 | } |
204 | - cacheEviction(relation, relation.getTo(), cache); | |
205 | 207 | } |
206 | 208 | |
207 | 209 | @Override |
... | ... | @@ -209,12 +211,12 @@ public class BaseRelationService implements RelationService { |
209 | 211 | Cache cache = cacheManager.getCache(RELATIONS_CACHE); |
210 | 212 | log.trace("Executing deleteEntityRelationsAsync [{}]", entity); |
211 | 213 | validate(entity); |
212 | - List<ListenableFuture<List<EntityRelation>>> inboundRelationsList = new ArrayList<>(); | |
214 | + List<ListenableFuture<List<EntityRelation>>> inboundRelationsListTo = new ArrayList<>(); | |
213 | 215 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { |
214 | - inboundRelationsList.add(relationDao.findAllByTo(entity, typeGroup)); | |
216 | + inboundRelationsListTo.add(relationDao.findAllByTo(entity, typeGroup)); | |
215 | 217 | } |
216 | - ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList); | |
217 | - ListenableFuture<List<Boolean>> inboundDeletions = Futures.transform(inboundRelations, | |
218 | + ListenableFuture<List<List<EntityRelation>>> inboundRelationsTo = Futures.allAsList(inboundRelationsListTo); | |
219 | + ListenableFuture<List<Boolean>> inboundDeletions = Futures.transform(inboundRelationsTo, | |
218 | 220 | (AsyncFunction<List<List<EntityRelation>>, List<Boolean>>) relations -> { |
219 | 221 | List<ListenableFuture<Boolean>> results = getListenableFutures(relations, cache, true); |
220 | 222 | return Futures.allAsList(results); |
... | ... | @@ -222,12 +224,12 @@ public class BaseRelationService implements RelationService { |
222 | 224 | |
223 | 225 | ListenableFuture<Boolean> inboundFuture = Futures.transform(inboundDeletions, getListToBooleanFunction()); |
224 | 226 | |
225 | - List<ListenableFuture<List<EntityRelation>>> inboundRelationsList1 = new ArrayList<>(); | |
227 | + List<ListenableFuture<List<EntityRelation>>> inboundRelationsListFrom = new ArrayList<>(); | |
226 | 228 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { |
227 | - inboundRelationsList1.add(relationDao.findAllByTo(entity, typeGroup)); | |
229 | + inboundRelationsListFrom.add(relationDao.findAllByTo(entity, typeGroup)); | |
228 | 230 | } |
229 | - ListenableFuture<List<List<EntityRelation>>> inboundRelations1 = Futures.allAsList(inboundRelationsList1); | |
230 | - Futures.transform(inboundRelations1, (AsyncFunction<List<List<EntityRelation>>, List<Boolean>>) relations -> { | |
231 | + ListenableFuture<List<List<EntityRelation>>> inboundRelationsFrom = Futures.allAsList(inboundRelationsListFrom); | |
232 | + Futures.transform(inboundRelationsFrom, (AsyncFunction<List<List<EntityRelation>>, List<Boolean>>) relations -> { | |
231 | 233 | List<ListenableFuture<Boolean>> results = getListenableFutures(relations, cache, false); |
232 | 234 | return Futures.allAsList(results); |
233 | 235 | }); |
... | ... | @@ -249,8 +251,10 @@ public class BaseRelationService implements RelationService { |
249 | 251 | private void checkFromDeleteAsync(Cache cache, List<ListenableFuture<Boolean>> results, EntityRelation relation, boolean isRemove) { |
250 | 252 | if (isRemove) { |
251 | 253 | results.add(relationDao.deleteRelationAsync(relation)); |
254 | + cacheEviction(relation, relation.getTo(), cache); | |
255 | + } else { | |
256 | + cacheEviction(relation, relation.getFrom(), cache); | |
252 | 257 | } |
253 | - cacheEviction(relation, relation.getTo(), cache); | |
254 | 258 | } |
255 | 259 | |
256 | 260 | private void cacheEviction(EntityRelation relation, EntityId entityId, Cache cache) { | ... | ... |