Firebase 实时数据库当前出现 TRIGGER_PAYLOAD_TOO_LARGE 错误
Firebase Realtime Database currently gives TRIGGER_PAYLOAD_TOO_LARGE error
从今天早上开始,我们的 Firebase 应用程序在向实时数据库实例写入 数据时出现问题。即使是最简单的任务,例如将一对键值对添加到对象也会触发
Error: TRIGGER_PAYLOAD_TOO_LARGE: This request would cause a function payload exceeding the maximum size allowed.
这特别奇怪,因为我们的代码或数据库在 24 小时内没有任何变化。
甚至像
这样简单的东西
Database.ref('environments/' + envkey).child('orders/' + orderkey).ref.set({a:1})
触发错误。
显然,有效负载的大小不是问题,但可能是什么原因造成的?
数据库结构,按要求
environments
+-env1
+-env2
--+orders
---+223344
-----customer: "Peters"
-----country: "NL"
-----+items
------item1
-------code: "a"
-------value: "b"
------item2
-------code: "x"
-------value: "2"
好的,我明白了。该问题与您的写入功能无关,但与写入操作将触发的云功能之一有关。
例如,我们有这样的结构:
/collections/data/abcd/items/a
在 JSON:
"collections": {
"data": {
"abc": {
"name": "example Col",
"itemCount": 5,
"items": {
"a": {"name": "a"},
"b": {"name": "b"},
"c": {"name": "c"},
"d": {"name": "d"},
"e": {"name": "e"},
}
}
}
}
对项目的任何写入都完全失败。 API、Javascript,甚至在控制台中进行基本写入。
我决定查看我们的云函数并发现:
const countItems = (collectionId) => {
return firebaseAdmin.database().ref(`/collections/data/${collectionId}/items`).once('value')
.then(snapshot => {
const items = snapshot.val();
const filtered = Object.keys(items).filter(key => {
const item = items[key];
return (item && !item.trash);
});
return firebaseAdmin.database().ref(`/collections/meta/${collectionId}/itemsCount`)
.set(filtered.length);
});
};
export const onCollectionItemAdd = functions.database.ref('/collections/data/{collectionId}/items/{itemId}')
.onCreate((change, context) => {
const { collectionId } = context.params;
return countItems(collectionId);
});
它本身没什么,但是触发读取所有项目并且默认情况下 firebase 云函数将整个快照发送到 CF,即使我们不使用它也是如此。事实上,它也发送之前和之后的值,所以如果你(像我们一样)此时有大量项目,我猜它试图发送到云函数的有效负载太大了。
我从我们的 CF 和 boom 中删除了计数功能,恢复正常。如果我们根本无法拥有触发器,则不确定 "correct" 进行计数的方法,但如果有,我会更新它...
TRIGGER_PAYLOAD_TOO_LARGE 错误是 Firebase 推出的一项新功能的一部分,我们的 existing RTDB limits 将在该功能中得到严格执行。进行更改的原因是为了确保我们不会静默删除任何 Cloud Functions 触发器,因为任何超过这些限制的事件都无法发送到 Functions。
您可以通过以下 REST 调用自行关闭此功能:
curl -X PUT -d "false" https://<namespace>.firebaseio.com/.settings/strictTriggerValidation/.json?auth\=<SECRET>
其中 <SECRET>
是您的
请注意,如果您禁用此功能,当前失败的请求可能会通过,但您拥有的任何触发超过我们限制的请求的 Cloud Functions 都将失败 运行。如果您正在为您的函数使用数据库触发器,我建议您重新构建您的请求,以便它们保持在限制范围内。
从今天早上开始,我们的 Firebase 应用程序在向实时数据库实例写入 数据时出现问题。即使是最简单的任务,例如将一对键值对添加到对象也会触发
Error: TRIGGER_PAYLOAD_TOO_LARGE: This request would cause a function payload exceeding the maximum size allowed.
这特别奇怪,因为我们的代码或数据库在 24 小时内没有任何变化。
甚至像
这样简单的东西Database.ref('environments/' + envkey).child('orders/' + orderkey).ref.set({a:1})
触发错误。
显然,有效负载的大小不是问题,但可能是什么原因造成的?
数据库结构,按要求
environments
+-env1
+-env2
--+orders
---+223344
-----customer: "Peters"
-----country: "NL"
-----+items
------item1
-------code: "a"
-------value: "b"
------item2
-------code: "x"
-------value: "2"
好的,我明白了。该问题与您的写入功能无关,但与写入操作将触发的云功能之一有关。
例如,我们有这样的结构:
/collections/data/abcd/items/a
在 JSON:
"collections": {
"data": {
"abc": {
"name": "example Col",
"itemCount": 5,
"items": {
"a": {"name": "a"},
"b": {"name": "b"},
"c": {"name": "c"},
"d": {"name": "d"},
"e": {"name": "e"},
}
}
}
}
对项目的任何写入都完全失败。 API、Javascript,甚至在控制台中进行基本写入。
我决定查看我们的云函数并发现:
const countItems = (collectionId) => {
return firebaseAdmin.database().ref(`/collections/data/${collectionId}/items`).once('value')
.then(snapshot => {
const items = snapshot.val();
const filtered = Object.keys(items).filter(key => {
const item = items[key];
return (item && !item.trash);
});
return firebaseAdmin.database().ref(`/collections/meta/${collectionId}/itemsCount`)
.set(filtered.length);
});
};
export const onCollectionItemAdd = functions.database.ref('/collections/data/{collectionId}/items/{itemId}')
.onCreate((change, context) => {
const { collectionId } = context.params;
return countItems(collectionId);
});
它本身没什么,但是触发读取所有项目并且默认情况下 firebase 云函数将整个快照发送到 CF,即使我们不使用它也是如此。事实上,它也发送之前和之后的值,所以如果你(像我们一样)此时有大量项目,我猜它试图发送到云函数的有效负载太大了。
我从我们的 CF 和 boom 中删除了计数功能,恢复正常。如果我们根本无法拥有触发器,则不确定 "correct" 进行计数的方法,但如果有,我会更新它...
TRIGGER_PAYLOAD_TOO_LARGE 错误是 Firebase 推出的一项新功能的一部分,我们的 existing RTDB limits 将在该功能中得到严格执行。进行更改的原因是为了确保我们不会静默删除任何 Cloud Functions 触发器,因为任何超过这些限制的事件都无法发送到 Functions。
您可以通过以下 REST 调用自行关闭此功能:
curl -X PUT -d "false" https://<namespace>.firebaseio.com/.settings/strictTriggerValidation/.json?auth\=<SECRET>
其中 <SECRET>
是您的
请注意,如果您禁用此功能,当前失败的请求可能会通过,但您拥有的任何触发超过我们限制的请求的 Cloud Functions 都将失败 运行。如果您正在为您的函数使用数据库触发器,我建议您重新构建您的请求,以便它们保持在限制范围内。