firebase - Ionic / Firebase 应用程序在后台后建立连接缓慢
问题描述
我有一个使用 Firebase 和 Angular 构建的 Ionic 应用程序。
我遇到了一个问题,当用户在空闲后返回应用程序并向下滑动以刷新提要时,有时需要 30 秒才能加载。
返回应用程序后,大约 70% 的刷新时间是即时的,有时我会在 8 小时后返回并向下滑动以刷新,这实际上是即时的。
但是,30% 的时间需要很长时间。也许30-40秒。它太长了,而且没有明显的原因。
我想知道是否有人知道这里可能存在什么问题。如果我不得不猜测我会说这是因为与 Firebase 的连接需要很长时间,但我不确定如何解决这个问题?它似乎也不是基于连接。
我的向下滑动代码:
doRefresh(refresher) {
this.goToNew(true);
refresher.complete();
}
并且this.goToNew()
是:
this.database.database.ref('/posts/'+this.feedId)
.orderByChild('created')
.limitToLast(10)
.once('value', (snapshot) => {
snapshot.forEach(child => {
this.feedCounter.push(child.val());
this.postFeed.push(child.val());
this.postFeed.sort(function(a,b){
return +new Date(b.created) - +new Date(a.created);
});
if(this.feedCounter.length >= 10) {
this.firstRun = false;
}
return false;
});
我不知道是什么导致了这个问题......有什么想法吗?
谢谢!
解决方案
发现它实际上是一个 Firebase 身份验证错误。
从后台返回后无法检查用户的身份验证,因此我的修复onAuthStateChanged
仅在平台为ready
. 即时建立火力基地连接!
this.platform.ready().then(() => {
this.afAuth.auth.onAuthStateChanged((user) => {
//code here
});
});
希望对某人有所帮助,因为这是一个奇怪的问题。
推荐阅读
- css - CSS - 3 列内容不那么响应
- excel - 在 excel 中比较 2 张(非常大)
- vb.net - 创建 HTTP 请求时设置请求标头
- audio - Pygame 中的声音问题
- windows - SVN cmd 更新而不恢复文件
- java - 什么是在 Java 中计时代码执行的干净方法?
- windows - 需要帮助编写批处理文件
- c# - MarkupExtension 对 Setter.Value 无效。唯一支持的 MarkupExtension 类型是 DynamicResourceExtension 和 BindingBase 或派生类型
- webpack - 使用 vue-cli 输出多个 webpack 构建
- sql - 正则表达式验证字符串是否是有效的 SQL 列名