Code Monkey home page Code Monkey logo

Comments (7)

lechim avatar lechim commented on June 27, 2024

Hi I made a quick work around function from the SDK to let this extension work on javascript Firebase functions.

const uuidv4 = require('uuid/v4');
const admin = require('firebase-admin');
const functions = require('firebase-functions');

exports.test = functions.https.onCall(async (data, context) => {
return await increment('visits', 'pages/clicks/test', 1);
});

function increment(field, path, val) {
const db = admin.firestore();
const increment = admin.firestore.FieldValue.increment(val);
const update = field.split(".").reverse().reduce((value, name) => ({[name]: value}), increment);
return doc.collection('_counter_shards_').doc(uuidv4()).set(update, {merge: true});
}

It may not be the best solution yet but works.

from extensions.

Ehesp avatar Ehesp commented on June 27, 2024

XFN Team: Would this be an additional "client" in the project, or would it be appropriate to adapt the web script to work in a Node environment?

from extensions.

Ehesp avatar Ehesp commented on June 27, 2024

Duplicate: #55

from extensions.

Henry- avatar Henry- commented on June 27, 2024

I think it would be better to adapt the web script to work in a Node environment.

I have tested the above code, and it triggers the aggregation function every time the "test" onCall function is called.

from extensions.

voxelbustersold avatar voxelbustersold commented on June 27, 2024

Won't increment provided by admin sdk work for distributed counter tasks?

from extensions.

jhuleatt avatar jhuleatt commented on June 27, 2024

@voxelbusters FieldValue.increment is the right thing for incrementing a value, but it doesn't solve the underlying problem that a Firestore document can only be updated about once per second. More info here.

from extensions.

jhuleatt avatar jhuleatt commented on June 27, 2024

We're not planning an official implementation for any other clients at this time, and we've changed the name of the "Web Client SDK" to "client sample" to try to make that a little more clear.

The typescript sample implementation is a good starting place for a node.js implementation of the counter.

In the future, I'd like to see how much of this logic we can move off of the client and into something like a callable function that's installed by the extension itself.

from extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.