Merge pull request #1532 from exoscale/fix/db-cache-miss

DAO: Hit the cache for entity flagged as removed tooI came along this part of the code and I don't see any reason why the cache should not be used when fetching with the "removed" ones. It will help decrease the number of DB queries.

*It can be merged in many CS versions*

* pr/1532:
  DAO: Rewrite change for method findByIdIncludingRemoved(ID id)
  dao: Hit the cache for entity flagged as removed too since they are put in cache afterwards.

Signed-off-by: Will Stevens <williamstevens@gmail.com>
This commit is contained in:
Will Stevens 2016-05-13 17:04:56 -04:00
commit 06c6b367e7

View File

@ -942,12 +942,18 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
@DB()
@SuppressWarnings("unchecked")
public T findById(final ID id) {
T result = null;
if (_cache != null) {
final Element element = _cache.get(id);
return element == null ? lockRow(id, null) : (T)element.getObjectValue();
if (element == null) {
result = lockRow(id, null);
} else {
result = (T)element.getObjectValue();
}
} else {
return lockRow(id, null);
result = lockRow(id, null);
}
return result;
}
@Override
@ -968,8 +974,19 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
@Override
@DB()
public T findByIdIncludingRemoved(ID id) {
return findById(id, true, null);
public T findByIdIncludingRemoved(final ID id) {
T result = null;
if (_cache != null) {
final Element element = _cache.get(id);
if (element == null) {
result = findById(id, true, null);
} else {
result = (T)element.getObjectValue();
}
} else {
result = findById(id, true, null);
}
return result;
}
@Override