Consistency model of Collection Read/Write

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:

Well, I see that you are using await and .then() which mostly likely causes some sort of conflict. In any case, it’s wrong.

You need to choose which method (only one ) that you want to use to handle the Promise: await, or .then().

@yisrael-wix Thanks for the response.

I agree that it’s better to avoid mixing await and then in the same function. But for this case, I am sure that it doesn’t cause the problem.

By the way, it seems that the problem disappeared just now. Every time I push the button, the counter is incremented by 10.

Did Wix push a fix ?

Seems that Wix finally provides an option to make sure the consistency: https://www.wix.com/velo/reference/wix-data/introduction#wix-data_introduction_wix-data-and-eventual-consistency