Browse Source

Update index.js

"parent" is now a property and no longer a method
Fixed the bounds so that the max chat messages do not exceed the MAX_LOG_COUNT value
master
Johan Vosloo 8 years ago
committed by GitHub
parent
commit
a8ca9a5e2c
  1. 6
      limit-children/functions/index.js

6
limit-children/functions/index.js

@ -23,13 +23,13 @@ const MAX_LOG_COUNT = 5;
// Removes siblings of the node that element that triggered the function if there are more than MAX_LOG_COUNT.
// In this example we'll keep the max number of chat message history to MAX_LOG_COUNT.
exports.truncate = functions.database.ref('/chat/{messageid}').onWrite(event => {
const parentRef = event.data.ref.parent();
const parentRef = event.data.ref.parent;
return parentRef.once('value').then(snapshot => {
if (snapshot.numChildren() > MAX_LOG_COUNT) {
if (snapshot.numChildren() >= MAX_LOG_COUNT) {
let childCount = 0;
const updates = {};
snapshot.forEach(function(child) {
if (++childCount < snapshot.numChildren() - MAX_LOG_COUNT) {
if (++childCount <= snapshot.numChildren() - MAX_LOG_COUNT) {
updates[child.key] = null;
}
});

Loading…
Cancel
Save