Page keeps crashing or loads so slow most devices cant load it! Help

I am at a complete lost for what my problem is here and when I called wix support they said there is code so it must be something with the code. Here is the code I have to to load on ready:

$w.onReady(function () {
wixData.query("NCChampionshipJudges")
.eq("_owner", userId)
.find()
.then((results) => {
console.log(results)
if (results.totalCount === 0) {
$w("#group1").show();
} else {
$w("#dataset1").onReady(() => {
console.log("dataset ready")
console.log(userId)
$w("#dropdown1").show();
$w("#welcomeback").show();
})
}
})
})

Also, the page is a member only page so if someone is not logged in, after they login it doesn’t do anything. Any ideas would be extremely helpful. The page currently has 1 dataset, a repeater that is collapsed on load to help speed up load. There are probably 5 text elements and a few buttons and user inputs that are hidden on load as well. I am at a lost and the site is live so any help would be amazing, this is really becoming problematic for me.

To make it easier to read/understand, I formatted your code and, after pasting it into this message, highlighted it and selected “Code Block” from the resultant menu (that keeps the formatting when viewed via this forum):

$w.onReady(function () {
  wixData.query("NCChampionshipJudges")
    .eq("_owner", userId)
    .find()
    .then((results) => {
console.log(results)
      if (results.totalCount === 0) {
        $w("#group1").show();
      } else {
        $w("#dataset1").onReady(() => {
console.log("dataset ready")
console.log(userId)
          $w("#dropdown1").show();
          $w("#welcomeback").show();
        })
      }
    })
})

Having done that, when you indicate that the site doesn’t do anything after the user logs in, I’m concluding from reading your code that are you indicating that nothing is showing; is that correct?

Also, what is the value of results that gets output to the console?

Thank you. So when someone is not logged in, nothing shows on console. It instantly goes to the member login window. Once you put in your information, it logs you in and then it doesn’t log anything, its like it doesn’t run the onReady after they log in and it stops running the onReady when they are not logged in. I am pretty stumped. And the speed thing is also pretty bad. Is the basic query I’m running to much on page load?

Update! Page seems to have a bug on the backside. When I created a new page, copier all the code, made it open to everyone and changed the database filter to current user it works great. Will post updated code but for some reason original page still won’t load. Appears to be a big of some kind. If anyone from wix sees this and wants to investigate, I have 3 different pages, 2 that seem to have the bug and one that is working perfect.

If you continue to have problems, please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

To add to this too, if you look at this Wix member profile tutorial here.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

You will see an example of how to do things when members login and logout etc. You can take the code and change the page setup to suit your own needs to make it fine for a members only area etc.

The only thing that you need to remember with this tutorial above, is that it works fine if you keep with the workings and link the user to another page after they login.

If you let the user login and keep them on the same page, which I think is also happening with your existing page, then you will need to refresh the page for the code to work.

After the user is logged in the page code needs to be restarted so to speak, so that it reloads with the user now seen as a logged in user and now shows all your hidden elements for example.

If you don’t refresh the page code, then the user will still be logged in, however the page will not recognise that fact and still show the non member status.

Especially if you have used your own custom light boxes to popup on the same page.