小编Vic*_*rez的帖子

使用Cloud Functions和Firestore的Firebase动态页面速度很慢

我们有动态页面Firebase云功能提供服务,但在TTFBTTFB的这些页面上速度非常慢900ms - 2s,起初我们只是认为这是一个cold start问题,但即使流量一致,它在TTFB的速度也非常慢700ms - 1.2s.

这对我们的项目来说有点问题,因为它依赖于自然流量,而Google Pagespeed需要服务器响应小于200ms.

无论如何,我们试图检查可能导致问题的原因,我们用Firestore查明了它,当Cloud Function访问Firestore时,我们注意到有一些延迟.这是我们如何实现Cloud Function和Firestore的基本示例代码:

dynamicPages.get('/ph/test/:id', (req, res) => {

    var globalStartTime = Date.now();
    var period = [];

    db.collection("CollectionTest")
        .get()
        .then((querySnapshot) => {

            period.push(Date.now() - globalStartTime);

            console.log('1', period);

            return db.collection("CollectionTest")
                .get();

        })
        .then((querySnapshot) => {

            period.push(Date.now() - globalStartTime);

            console.log('2', period);

            res.status(200)
                .send('Period: ' + JSON.stringify(period));

            return true;

        })
        .catch((error) => {

            console.log(error);
            res.end();

            return false;

        });

});
Run Code Online (Sandbox Code Playgroud)

这是在Firebase + …

node.js firebase google-cloud-functions google-cloud-firestore

12
推荐指数
1
解决办法
500
查看次数

Firebase 应用初始化失败,凭证无效(firebase 函数初始化)

根据文档

如果您在 Cloud Function 中使用 Node.js Admin SDK,则可以通过 functions.config() 变量自动初始化 SDK:

admin.initializeApp(functions.config().firebase);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这段非常简单的代码时:

const functions = require('firebase-functions')
const admin = require('firebase-admin')

admin.initializeApp(functions.config().firebase)

exports.orhub = functions.https.onRequest((req, res) => {
    res.end()
})
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: invalid_grant (Bad Request)\". There are two likely causes: (1) your server time is not properly synced or (2) …
Run Code Online (Sandbox Code Playgroud)

node.js firebase

7
推荐指数
2
解决办法
8586
查看次数

firebase_screen_class 是什么意思

我现在正在使用 Firebase Analytics 来分析有关应用程序的数据,我对这个领域很陌生。在BigQuery中,我发现在在session_start事件现场,有一个叫子firebase_screen_class并有像一些子类FirstViewControllerUIAlertControllerpreferencetableviewCotrollerPagescrollviewController。我试图弄清楚这些意味着什么,并且知道这些与 IOS 应用程序开发有关。有没有人可以帮助我更好地理解这些术语或给我一些有用的链接让我学习自己?

谢谢!!!

ios firebase

6
推荐指数
1
解决办法
2380
查看次数

如何解决“无法将文件保存到不存在的目录:'{parent}'”错误?

我想将“df”保存到“数据集”文件。

这是我的代码代码文件名为“practice.py”

import pandas as pd

df = pd.DataFrame({
    "x1": [100000, 200000, 300000],
    "x2": [400000, 500000, 600000],
    "x3": [700000, 800000, 900000]},

     index=[2019, 2021, 2020]

)
df.index.name = 'year' # set the index name

df.to_csv('dataset/covid_dataset.csv', encoding='utf-8') # save to file
Run Code Online (Sandbox Code Playgroud)

我认为我的文件路径设置得很好,但我不知道错误在哪里。

这是我的文件结构:

在此输入图像描述

这是错误消息:

(covid_project) C:\self_project\covid_project>C:/self_project/covid_project/Scripts/python.exe c:/self_project/covid_project/covid19_project/practice.py
Traceback (most recent call last):
  File "c:\self_project\covid_project\covid19_project\practice.py", line 13, in <module>
    df.to_csv('dataset/covid_dataset.csv', encoding='utf-8')
  File "C:\self_project\covid_project\lib\site-packages\pandas\core\generic.py", line 3563, in to_csv
    return DataFrameRenderer(formatter).to_csv(
  File "C:\self_project\covid_project\lib\site-packages\pandas\io\formats\format.py", line 1180, in to_csv
    csv_formatter.save()
  File "C:\self_project\covid_project\lib\site-packages\pandas\io\formats\csvs.py", line 241, in save
    with …
Run Code Online (Sandbox Code Playgroud)

python pandas

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

Sonarqube - 最后一次分析失败。后台任务页面上提供了更多详细信息

我试图使用 Sonarqube 分析我们的代码库。重构特定文件“ReportHelper.java”后,最后一次分析失败。

Caused by: java.lang.IllegalStateException: Fail to process issues of
    component
    'com.vls.nost:Nost_business:src/main/java/com/velos/nost/business/helper/ReportHelper.java'
        at
    org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor.visitAny(IntegrateIssuesVisitor.java:70)
        at
    org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorWrapper.visitAny(TypeAwareVisitorWrapper.java:82)
        at
    org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler.visitNode(VisitorsCrawler.java:117)
        at
    org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler.visitImpl(VisitorsCrawler.java:100)
        at
    org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler.visit(VisitorsCrawler.java:72)
        ... 26 more Caused by: java.lang.IllegalStateException: Source of
    file
    'ComponentImpl{key='com.velos.nostradamus:Nostradamus_business:src/main/java/com/vls/nost/business/helper/ReportHelper.java',
    type=FILE, uuid='AWKq2KypGCJ2XfmqS536',
    name='com.vls.nostradamus:Nostradamus_business:src/main/java/com/vls/nost/business/helper/nost.java',
    description='null', fileAttributes=FileAttributes{languageKey='java',
    unitTest=false, lines=3611}, reportAttributes=ReportAttributes{ref=67,
    version='null',
    path='src/main/java/com/vls/nost/business/helper/ReportHelper.java',
    scmPath='business/src/main/java/com/velos/nost/business/helper/ReportHelper.java'}}'
    has less lines (3512) than the expected number (3611)
Run Code Online (Sandbox Code Playgroud)

不确定,为什么重构后行数不能少于预期的行数?另外,我想知道声纳是如何得出这个预期数字的?

任何帮助将非常感激?

java analysis sonarqube

5
推荐指数
0
解决办法
8738
查看次数

从 Android 中调用 Firebase Cloud Function 接收数据

我正在尝试调用我编写的 firebase 云函数。

我已经使用 Postman 测试了该功能来模拟 HTTP 请求。这是我在 Postman 中调用我的函数时的 JSON 结果:

{
 "groups": [
    {
        "isPublic": true,
        "members": [
            true
        ],
        "numberOfMembers": 1,
        "groupId": "-LAOPAzMGzOd9qULPxue"
    },
    {
        "isPublic": true,
        "members": [
            true
        ],
        "numberOfMembers": 1,
        "groupId": "-LAOP7ISDI2JPzAgTYGi"
    }
 ]
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试执行相同的操作并在我的 android 应用程序中检索此 JSON 列表。我正在关注 Firebase 网站上的示例:https ://firebase.google.com/docs/functions/callable

这是 Firebase 关于如何检索数据的示例:

return mFunctions
        .getHttpsCallable("addMessage")
        .call(data)
        .continueWith(new Continuation<HttpsCallableResult, String>() {
            @Override
            public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                String result = (String) task.getResult().getData();
                return result;
            }
        });
Run Code Online (Sandbox Code Playgroud)

目前尚不清楚如何从我的云功能中获取结果并将其用于我的 …

java android firebase

5
推荐指数
1
解决办法
3656
查看次数

子集合的更改是否应该触发 onWrite 函数?

Firebase 函数是否可以通过subcollections函数侦听顶级文档时的更改触发?如果不是,文档通配符示例中的第一行是什么意思?

这是什么意思???如果子集合更改会触发该功能吗?但它似乎没有,同一页面中的其他地方也这么说。

// Listen for changes in all documents and all sub-collections
Run Code Online (Sandbox Code Playgroud)

...

exports.useWildcard = functions.firestore
  .document('users/{userId}')
  .onWrite((event) => {
    // If we set `/users/marie` to {name: "marie"} then
    event.params.userId == "marie"
    // ... and ...
    event.data.data() == {name: "Marie"}
  });
Run Code Online (Sandbox Code Playgroud)

Firestore 和函数触发器的预期行为是什么

firebase google-cloud-firestore

4
推荐指数
1
解决办法
4317
查看次数

DOM Element.Closest Child

在查询DOM时,是否有任何理由为什么标签不能作为孩子使用?

var el = document.getElementById("myEl");
var group = el.closest(".form-group");
var ipt =  el.closest(".form-group > input");
var lbl =  el.closest(".form-group > label");
console.log(ipt);
console.log(lbl);
Run Code Online (Sandbox Code Playgroud)
<div class="row">
  <div class="form-group col-sm-6">
    <label>Name
      <i class="fa fa-asterisk text-danger"></i>
    </label>
    <input type="text" class="form-control" id="myEl" value.bind="location.name & validate">
  </div>
</div>
    
Run Code Online (Sandbox Code Playgroud)

html javascript dom

4
推荐指数
1
解决办法
2897
查看次数

Pycharm:为Google服务帐户密钥设置环境变量(json凭证)

我想在我的pycharm中运行google cloud speech python示例.

但遇到了

ApplicationDefaultCredentialsError:应用程序默认凭据不可用.如果在Google Compute Engine中运行,则可以使用它们.否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向定义凭证的文件.有关详细信息,请参阅https://developers.google.com/accounts/docs/application-default-credentials.

我试过这个解决方案,但它不起作用.谁能帮我?谢谢!

PS:谷歌样本可以在终端中运行良好.

python pycharm google-cloud-platform google-cloud-speech

3
推荐指数
1
解决办法
1675
查看次数

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