简体   繁体   English

您可以进行身份验证,然后使用 Cloud Firestore 对数据发出多个相关请求吗?

[英]Can you authenticate, then make multiple dependent requests for data using Cloud Firestore?

In my app, a user can log in, then a list of their "pages" (a collection of documents) is retrieved, and their "selectedPageId" is retrieved.在我的应用程序中,用户可以登录,然后检索他们的“页面”(文档集合)列表,并检索他们的“selectedPageId”。 This way the UI can show a list of page names, and the content of the selected page.这样,UI 可以显示页面名称列表以及所选页面的内容。

This means three requests have to happen, each waiting for the other:这意味着必须发生三个请求,每个请求都在等待另一个:

  • log in登录
  • get list of pages获取页面列表
  • get selected page id获取选定的页面 id

Is there a way to make all this happen on the server at once so I can make a single request, which I assume would make my UI render more quickly?有没有办法让这一切立即在服务器上发生,这样我就可以发出一个请求,我认为这会使我的 UI 渲染得更快?

As Dharmaraj mentioned in his comment, "Firebase Auth will still be required on client side".正如 Dharmaraj 在他的评论中提到的那样,“客户端仍然需要 Firebase 身份验证”。 However , is you use the default Auth state persistence (ie firebase.auth.Auth.Persistence.LOCAL ) once a user is signed in he/she doesn't need to sign in the next times ("the state will be persisted even when the browser window is closed. An explicit sign out is needed to clear that state"). However , is you use the default Auth state persistence (ie firebase.auth.Auth.Persistence.LOCAL ) once a user is signed in he/she doesn't need to sign in the next times ("the state will be persisted even when浏览器 window 已关闭。需要显式注销才能清除该状态“)。 So signing in is not really a problem IMO.因此,登录实际上并不是 IMO 的问题。

For the Firestore queries: Executing the two queries back-to-back with the second one returning only one document should not take a lot of extra time compare to executing only the first query (which fetches the pages list).对于 Firestore 查询:与仅执行第一个查询(获取页面列表)相比,与仅返回一个文档的第二个查询背靠背执行两个查询不应该花费很多额外的时间。


Having said that, one possible approach would be to save, for each user, a Firestore document containing the list of the user's pages plus the user's selectedPageId .话虽如此,一种可能的方法是为每个用户保存一个 Firestore文档,其中包含用户的页面列表以及用户的selectedPageId You can maintain this page with a Cloud Function which, for example, mirrors the list (documents in a collection) with an array in this Firebase doc.您可以使用 Cloud Function 维护此页面,例如,使用此 Firebase 文档中的数组镜像列表(集合中的文档)。 However, you need to take care to not reach the maximum size for a document ie 1MiB (hence my question on the number of fields displayed for a page).但是,您需要注意不要达到文档的最大大小,即 1MiB(因此我对页面显示的字段数提出了疑问)。

One possible variation in this case would be to initially present, in your first app page, a limited number (eg 25) of pages of the list, with a "Show more" button.在这种情况下,一种可能的变化是最初在您的第一个应用程序页面中显示有限数量(例如 25)的列表页面,并带有“显示更多”按钮。


Finally, note that using a Cloud Function as mentioned in the above comments will very most probably increase the response time compare to standard queries executed via the SDK.最后,请注意,与通过 SDK 执行的标准查询相比,使用上述评论中提到的 Cloud Function 很可能会增加响应时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 云中的 Firestore function 需要几分钟来初始化并发出第一个请求 - Firestore in cloud function takes a few minutes to initialize and make first requests 用数据填充 indexedDb,因此您无需使用 Firestore 发出第二个请求 - Filling indexedDb with data, so you don't need to make a second request using Firestore Firebase 云存储规则能否针对 Firestore 数据进行验证? - Can Firebase Cloud Storage rules validate against Firestore data? 无法在 flutter 应用中从 Cloud Firestore 获取数据 - Can't Get data from Cloud Firestore in flutter app FLUTTER:如何在cloud firestore 中使用where 子句删除多个文档? - FLUTTER: How to delete multiple documents using where clause in cloud firestore? 如何使用 flutter 和 dart 从 Cloud Firestore 检索特定数据? - how to retrieve specific data from Cloud Firestore using flutter and dart? 如何在 cloud firestore 的 CollectionReference 中添加 DocumentID? 使用 flutter - How can i add DocumentID in CollectionReference of cloud firestore? Using flutter Cloud Firestore 触发器运行多次 - Cloud Firestore triggers run multiple times Firestore 社交媒体好友请求数据 model - Firestore social media friend requests data model 如何使用 Angular 5 中的批量写入从 Cloud Firestore 中删除多个文档 - How to delete multiple documents from Cloud Firestore using Batched writes in angular 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM