Firebase:客户端事务和云函数事务之间有区别吗?

Firebase: Is there a difference between client transactions and cloud function transactions?

正如所指出的 here 我正在尝试找到一种方法来显示 post 与 Firebase 的趋势。

由于我看不到其他方法可以解决这个问题,所以我决定采用冗余方式:

-trendingToday
    -$date
        -$postId
            -numberOfLikes // negative number for descending order

-trendingMonth
    -$date
        -$postId
            -numberOfLikes // negative number for descending order

当用户喜欢 post 时,第一个 trendingToday/$date/$postId/numberOfLikes 通过交易减少 1。然后应该有一个 for-loop 来减少 trendingMonth/$date/$postId/numberOfLikes 中的数字,其中 $date 循环接下来的 30 天。这也应该与事务一起执行。

现在的问题是:我是在客户端执行此逻辑更好,还是最好使用云函数来解决?

如果您选择在客户端上执行大量工作,如果用户终止应用程序或失去连接或其他一些中断,工作可能无法全部完成。

云函数在其执行过程中不太可能被打断,因此您的所有事务更有可能一致地完成。