allinbits / dither

Transparent, uncensorable chat on the Cosmos Hub.
https://dither.chat
14 stars 2 forks source link

Fetching bug #28

Closed fadeev closed 4 years ago

fadeev commented 4 years ago

There is a bug with fetching memos.

To reproduce visit a user profile and open Vue devtools. Notice that there are over 100 memos in Vuex, although the profile may only show 10.

Screenshot 2020-03-23 at 19 35 08

That's not perfect (a user should not have to download memos that he doesn't see on the page), but it becomes a problem after visiting other pages or even waiting for a short while. Either devtools blow up (this happens so often to me, that it makes it hard to debug the app):

Screenshot 2020-03-23 at 19 35 48

Or call stack error is raised:

Screenshot 2020-03-23 at 13 47 58
fadeev commented 4 years ago

I've located the source of the error to the following line in App.vue:

this.following.map(address => this.fetchMemosFromAddress(address));

This line makes the user fetch memos uncontrollably. This line also doesn't make sense, because map returns an array of undefined, which gets discarded. fetchMemosFromAddress produces side-effects, and I assume forEach was meant to be used to fetch memos for each address. This does not solve the problem above, however.

To fix this I propose we delegate the important task of fetching memos and other page-specific data to pages themselves (and avoid doing that globally in App.vue). For example, a profile page will dispatch events to fetch memos required for this page (and nothing more). So will the home page. BtnLoadMore on the other hand, should be a presentational component and should not be dispatching Vuex events, but rather should send events to whatever parent it has, so that the parent can handle data fetching.

To start doing this, it's important to be able to fetch only the right data, for example, in AccountsAccount.vue:

    this.$store.dispatch("memos/fetchAndAdd", {
      limit: 10,
      orderBy: ["timestamp", "desc"],
      where: [
        ["address", "==", this.$route.params.address],
        ["type", "==", "post"]
      ]
    });

Fetching posts made from a specific address. I've added ["type", "==", "post"], but if fails:

Screenshot 2020-03-23 at 19 45 47

https://github.com/virgo-project/dither/tree/fadeev/fetching

@nylira would like to hear your thoughts on this! If you agree, we should create indexes, so we can query data more precisely (I don't have permissions to do this).

nylira commented 4 years ago

Hey Denis, I'm happy to create this index to so that you can resolve this bug. Can you give me the exact Firebase URL from your Chrome console?

fadeev commented 4 years ago

https://console.firebase.google.com/v1/r/project/ditherchat/firestore/indexes?create_composite=Ckhwcm9qZWN0cy9kaXRoZXJjaGF0L2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9tZW1vcy9pbmRleGVzL18QARoLCgdhZGRyZXNzEAEaCAoEdHlwZRABGg0KCXRpbWVzdGFtcBACGgwKCF9fbmFtZV9fEAI

nylira commented 4 years ago

It's ready to go

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.