Hi, I wonder what is the consistency model of Corvid collection access.
As of today, I found that after updating an item in a collection, then soon retrieving the item, the old item (before updated) is sometimes returned. Is it intented behavior ?
I created a test site here: https://opi544.editorx.io/mysite-5/updatecollection
When the button is clicked, backend code is called to increment a counter of a collection entry 10 times using for-loop.
Front end code:
import { updateCollection } from 'backend/updateCollection.jsw'
$w.onReady(function () {
});
export async function button1_click(event) {
console.log(await updateCollection());
}
Backend code:
import wixData from 'wix-data';
export async function updateCollection(factor1, factor2) {
let ret = [];
for (let i = 0; i < 10; i++) {
// retrieve item
let data = await wixData.query("TestCollection")
.find({ suppressAuth: true })
.then(result => {
return result.items[0];
});
// push the current counter value for verification
ret.push(data.info.ctr);
// increment counter, then update collection
data.info.ctr++;
await wixData.update('TestCollection', data, { suppressAuth: true });
}
return ret;
}
I expect that the returned counter values are incremented array of values (e.g. 10,11,12,…,19). However, it appears that retrieving the item soon after updating it, sometimes returned old value (before the update).
Here is what is returned by the above code: