小编Yos*_*oto的帖子

firestore数据结构的最佳实践是什么?

我正在使用firebase创建一个博客应用程序.

我想知道数据结构的最佳实践.

据我所知,有2个案例.(我正在使用本机反应)

情况1:

posts
  -postID
   -title,content,author(userID),createdDate,favoriteCount

favorites
  -userID
    -favoriteList
      -postID(onlyID)
      -postID(onlyID)
Run Code Online (Sandbox Code Playgroud)

在这种情况下,例如,当我们需要获得最喜欢的帖子时.

firebase.firestore().collection(`favorites/${userID}/favoriteList`)
    .get()
    .then((snapshot) => {
      snapshot.forEach((favorite) => {
        firebase.firestore().collection(`favorites/`).doc(`${favorite.id}`)
          .get()
          .then((post) => {
          myPostList.push(post.data())
        });
  });
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我们无法订购最喜欢的帖子createdDate.所以,需要对客户端进行排序.即使这样,我们也不使用limit()函数.

案例2:

posts
  -postID
  -title,content,author(userID),createdDate,favoriteCount

favorites
  -userID
     -favoriteList
       -postID
         -title,content,author(userID),createdDate,favoriteCount
       -postID
         -title,content,author(userID),createdDate,favoriteCount
Run Code Online (Sandbox Code Playgroud)

firebase.firestore().collection(`favorites/${userID}/favoriteList`).orderBy('createdDate','desc').limit(30)
    .get()
    .then((snapshot) => {
      snapshot.forEach((post) => {
        myPostList.push(post.data())
      });
  });
Run Code Online (Sandbox Code Playgroud)

在这种情况下,当作者修改收藏帖子时,我们必须更新所有喜爱的帖子.(例如,如果100个用户将帖子保存为收藏,我们必须更新为100个数据.)

(而且我不确定我们可以favoritecount通过交易增加,完全相同.)

我想如果我们使用firebase.batch(),我们可以管理它.但我认为这似乎效率低下.

似乎两种方式都不完美.你知道这个案子的最佳做法吗?

javascript nosql firebase react-native google-cloud-firestore

6
推荐指数
2
解决办法
3975
查看次数

如何等待协程回调执行?

我想等待 StartCoroutine 回调被执行。有人知道该怎么做吗?

public float getXXX() {
  var result;
  StartCoroutine(YYY((r) => result = r)); // how to wait this?
  return result;
}

private IEnumerator YYY(System.Action<float> callback) {
  LinkedList<float> list = new LinkedList<float>();
  while(timeleft > 0) {
    timeleft -= Time.deltaTime;
    list.add(transform.position.magnitude);
    yield return new WaitForSeconds (WAITSPAN);
  }

  callback(list.max());
  yeild return true;
}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

2
推荐指数
1
解决办法
1万
查看次数

如何在 @0.21.0 上解决 tetscafe 上的问题(testcafe-live 不起作用)

testcafe 版本从 0.21 升级到 0.23 以上后,我们遇到了 testcafe-live 不工作的问题。

命令。

testcafe-live chrome tests/menu/test0001.ts --screenshots my-fixture/chrome --trace-warnings
Run Code Online (Sandbox Code Playgroud)

控制台消息

(node:9808) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
at new TestRunner (D:\business\comp\Git\autotest\node_modules\testcafe-live\lib\test-runner.js:36:46)
at Controller.init (D:\business\comp\Git\autotest\node_modules\testcafe-live\lib\controller.js:26:27)
at tcArguments.parse.then (D:\business\comp\Git\autotest\node_modules\testcafe-live\lib\index.js:16:28)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
(node:9808) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection …
Run Code Online (Sandbox Code Playgroud)

testing automated-tests node.js npm testcafe

2
推荐指数
1
解决办法
411
查看次数