Repeater loads before it is filtered properly

I need my repeater to load after all the filtering is done. Sometimes it works perfectly fine, other times incorrect items flash and then the repeater shows the correct items. I tried the hide on load/show method but the problem is still there. I also tried to use await/then but I don’t know if I am using them properly. Here is the code for the page:

let user = wixUsers.currentUser;

$w.onReady(function () {
    $w('#button17').onClick(async (event, $w) => {
        wixData.query("userProfile")
            .eq("_owner", user.id)
            .find()
            .then((results) => {
                let Item = results.items[0];
                let toInsert = {
                     "liked": $w('#dataset1').getCurrentItem()._id,
                     "userthatliked": Item
                };
                wixData.insert('Liked', toInsert);
            })
        $w('#button17').label = "Contact Info Sent";
    });

    $w("#dataset1").onReady(async () => {
        wixData.query("userProfile")
            .eq("_owner", user.id)
            .find()
            .then((results) => {
                 let firstItem = results.items[0];
                 if (firstItem.gender === 'Male') {
                    $w('#button18').label = 'Female'
                 } else { $w('#button18').label = 'Male' }
                 if ($w('#button18').label !== null) {
                    $w("#dataset1").setFilter(wixData.filter().ne("gender",                            firstItem.gender));
                    $w("#repeater1").show();
                }
                 if ($w('#button18').label === null) {        wixWindow.openLightbox("Profile Setup"); }
            })
    });
});

I really need help with this, as my website depends on this working properly. I would really appreciate if anyone can tell me what’s wrong with the code.

Putting a .then clause on there will ensure that the repeater doesn’t appear until the filter is applied:

    $w("#dataset1").setFilter(wixData.filter()
       .ne("gender",firstItem.gender)
    )
    .then(() => {
        $w("#repeater1").show();
    })