I need to optimize the read/write count for a POST request that I’m using.
Some info about the request:
- The user sends a JSON array of ~100 items
- The servlet needs to check if any of the received items is newer then its counterpart in the datastore using a single
longattribute - I’m using JDO
what i currently do is (pseudo code):
foreach(item : json.items) {
storedItem = persistenceManager.getObjectById(item.key);
if(item.long > storedItem.long) {
// Update storedItem
}
}
Which obviously results in ~100 read requests per request.
What is the best way to reduce the read count for this logic? Using JDO Query? I read that using “IN”-Queries simply results in multiple queries executed after another, so I don’t think that would help me 🙁
There also is PersistenceManager.getObjectsById(Collection). Does that help in any way? Can’t find any documentation of how many requests this will issue.
I think you can use below call to do a batch get:
Something like above query would return all objects you need.
And you can handle all the rest from here.