-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DAO: Hit the cache for entity flagged as removed too #1532
Conversation
in cache afterwards.
if (_cache != null) { | ||
final Element element = _cache.get(id); | ||
return element == null ? findById(id, true, null) : (T)element.getObjectValue(); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else clause is unnecessary due the return in preceding if clause. Please remove it to simplify the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jburwell if _cache == null a return needs to be there (or a throw of some sort)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dahn if the _cache
is not optional then I agree. It should probably be something like the following:
if (_cache == null) {
throw new IllegalStateException("The cache has not been properly initialized for DAO " + this.getClass().getSimpleName());
}
final Element element = _cache.get(id);
return element == null ? findById(id, true, null) : (T) element.getObjectValue();
Would you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but I think the submitted code suggest it is optional:
T result = findById(id, true, null)
if (_cache != null) {
final Element element = _cache.get(id);
if (element != null) {
result = (T)element.getObjectValue();
}
}
return result;
I have no problem with the proposed code if _cache is optional however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for the existence of the cache is made on other lines in this class, so I kept it. My change is to use the cached value if there is one, as it wasn't the case before.
The function looks pretty much the same as the findById
(line 944).
@DaanHoogland in your last code sample, on the first line you go first to the DB to retrieve the object. Then if the cache isn't null, you fetch the value from the cache and discard the one you just got. IMO it's a downgrade in terms of performance as you never use directly the value in cache but always do a query against the DB.
@jburwell I could change the code as you're suggesting, but then the exception should be raised at other places too to keep the code consistent when the cache isn't configured, which wasn't my initial goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcaurele good point so to address your concern:
T result = null
if (_cache != null) {
final Element element = _cache.get(id);
if (element != null) {
result = (T)element.getObjectValue();
}
} else {
result =findById(id, true, null);
}
return result;
this also implements the good practice of having only one return in the method. I am not hellbound on these changes however. As the method is so small it would be merely cosmetic.
@DaanHoogland I agree that's the best practice though there is a glitch here. Following code returns null if _cache is not null but element is null, T result = null
if (_cache != null) {
final Element element = _cache.get(id);
if (element != null) {
result = (T)element.getObjectValue();
}
} else {
result =findById(id, true, null);
}
return result; |
Probably intention is to, T result = null
if (_cache != null) {
final Element element = _cache.get(id);
if (element != null) {
result = (T)element.getObjectValue();
} else {
result = findById(id, true, null);
}
}
return result; |
@sateesh-chodapuneedi not quite, you're missing a case. If the cache is null (not configured) you will always return |
I pushed a change to write the method following the good practive you're mentioning. I also updated the sibling method findById to follow the same practice. |
@marcaurele @sateesh-chodapuneedi You are both right probably more then I will ever be so please take with a grain of salt:
same pattern would apply to the findIncludingRemoved variety. I think this is the cleanest though Marc's version should be semantically equal given a good optimising compiler. |
} | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a ';' missing :(
4682381
to
e7ad942
Compare
LGTM based on code, CI pending |
Thanks @DaanHoogland. 👍 |
@swill I am getting to many false positives in my environment to grant it value, can you schedule this for integration testing? |
@DaanHoogland I am also getting more false negatives than I had in the past. I am also pushing my environments a bit harder than I was before, so I think that is part of it. I will add this one to my CI. |
CI RESULTS
Summary of the problem(s):
Associated Uploads
Uploads will be available until Comment created by |
I reran the tests that failed and they succeeded the second time, so CI is in a good place on this one. I need one more code review on this one. @marcaurele can you please force push this PR to kick of Jenkins again so when we get another code review we can merge right away. Thanks... |
e7ad942
to
56fe0ec
Compare
@swill did a force push by changing the last commit description |
Thank you sir. Unfortunately travis failed this time. Would you mind trying it again. Thanks... |
@marcaurele instead of force push you can close and reopen after a few seconds. This usually works as well and seves you switching windows browser->terminal->browser ;) |
I don't get what's the relation between my change and the jenkins build failling. Should I trigger another one? |
@marcaurele I don't think it is related to your code either. can you open/close your pr to see if it works. If not, maybe we need to empty the jenkins-workspace. The problems are not clear to me, might be jenkins, our job or something messy in our code. Any pointers are welcome. |
56fe0ec
to
648e06c
Compare
Once I get #1539 merged, I will ask you to re-push since we are working to fix the issue that is causing Travis to fail in that PR right now. Thx... |
@marcaurele I have merged fixes to Jenkins and Travis, can you force push again to kick off those runs again. Sorry for the inconvenience, hopefully this is the last time. :P |
648e06c
to
28d0bd3
Compare
Sorry to do this to you again @marcaurele. Can you rebase and force push again. I have disabled the test in |
28d0bd3
to
2685eb4
Compare
Also change the sibling method findById(final ID id)
2685eb4
to
39aa0e4
Compare
checks are finally ok... |
I am counting my own code review on this one given the scope of the change and the fact that a review is the only thing holding this up. I will merge this one... |
@swill you should always count the opinion of the RM as that of a real memeber of the community ;) |
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 <[email protected]>
I 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