Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay before disconnecting useFirestore #2252

Closed
4 tasks done
Zehir opened this issue Sep 25, 2022 · 12 comments
Closed
4 tasks done

Delay before disconnecting useFirestore #2252

Zehir opened this issue Sep 25, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@Zehir
Copy link
Contributor

Zehir commented Sep 25, 2022

Clear and concise description of the problem

In the case you are using vue-plugin-pages you can have a case that you load the same documents multiple times in case you came back to a page you already loaded once.
But when you change the page the connection is closed at the moment you left the page thanks to:

    tryOnScopeDispose(() => {
      close()
    })

So you will be charged by one read each time.

Suggested solution

Using a little delay could alow you to use the cached document instead of get one new.

    tryOnScopeDispose(() => {
      useTimeoutFn(() => {
        close()
      }, 30000)
    })

You don't need more code because the firestore sdk handle it by default. Even if the first useFirestore is closed I still get updates on the new useFirestore

Alternative

An alternative is to store your useFirestore in a pinia store but it's lead to many tracks of what you put there.

Additional context

I can make a PR for that but I don't know about the delay, should it's be lower ? configurable ?
Maybe a force close option ?
Maybe a close if I get an update during the timeout ?

Validations

@Zehir Zehir added the enhancement New feature or request label Sep 25, 2022
@kiyopikko
Copy link
Contributor

I think it's the simplest way autoDispose option also accept milliseconds of timeout (number) not only false.

Maybe a close if I get an update during the timeout ?

Can you do this? I want to know how it is implemented.

@Zehir
Copy link
Contributor Author

Zehir commented Sep 26, 2022

I will make a PR to have some code to discuss on. But yes you can do that with a watchOnce and call the close method when data is updated. If it's an other listener on the same document it's won't be an issue because it's will just close the old one.

@Zehir
Copy link
Contributor Author

Zehir commented Sep 26, 2022

This is my current implementation using a custom composable;
https://gist.github.com/Zehir/be3b229e36963b1e4d6869207b231ac0

@kiyopikko
Copy link
Contributor

Thanks, let's discuss on your PR 👍

@Zehir
Copy link
Contributor Author

Zehir commented Sep 28, 2022

Thanks, let's discuss on your PR 👍

It's may take a few days, I have some issues to setup a dev env #2268

@Zehir
Copy link
Contributor Author

Zehir commented Sep 29, 2022

@kiyopikko why did you limit close to query only ? Documents read need to be closed too.

if (autoDispose && !isDocumentReference<T>(refOfDocRef.value)) {
tryOnScopeDispose(() => {
close()
})
}

@kiyopikko
Copy link
Contributor

@Zehir oh, that's a mistake and thanks for making PR!

I cared about compatibility, I wanted to write

if (autoDispose || isDocumentReference<T>(refOfDocRef.value)) { 
  tryOnScopeDispose(() => {})
}

because documents always close regardless autoDispose option in previous code.

but almost users will expect to be able to use autoDispose to documents so

if (autoDispose) { 
  tryOnScopeDispose(() => {})
}

is good like your PR.

@stale
Copy link

stale bot commented Nov 29, 2022

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.

@stale stale bot added the stale label Nov 29, 2022
@Zehir
Copy link
Contributor Author

Zehir commented Nov 29, 2022

Up

@stale stale bot removed the stale label Nov 29, 2022
@stale
Copy link

stale bot commented Jan 28, 2023

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.

@stale stale bot added the stale label Jan 28, 2023
@Zehir
Copy link
Contributor Author

Zehir commented Jan 28, 2023

#2276 is updated

@stale stale bot removed the stale label Jan 28, 2023
@stale
Copy link

stale bot commented Mar 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants