Coder Social home page Coder Social logo

Vote count not updated about app HOT 5 CLOSED

dnlkng avatar dnlkng commented on September 14, 2024
Vote count not updated

from app.

Comments (5)

leolabs avatar leolabs commented on September 14, 2024

Some fields are updated by Cloud Functions. You might have to deploy them in your Firebase project to make this work. Using the command firebase deploy --only functions should do the trick.

from app.

dnlkng avatar dnlkng commented on September 14, 2024

Thank you for your fast response. I think I have all functions in firebase up to date. There is a function called processVotes in my dashboard what should do the magic. It is the only function marked as Trigger ref.write the others are all HTTP Anfrage (I think request).

from app.

dnlkng avatar dnlkng commented on September 14, 2024

I think I found the root of the issue. Due to an misconfiguration of firebase, I had two realtime databases. One in europe-west1 (my standard db) and one in us-central1 where the functions live too (I think I created the second one because of a mismatch of the region of the functions and the db. But I'm not sure).

All data was written to the second db (us-cetnral1). But the function processVotes watched changes and would like to write in the first db. So it didn't do anything and no vote count was updated for the tracks. I close the issue because of the configuration failure.

I read in the firebase documentation changing the default db of firebase is not possible. And it seems the key for databaseURL in firebase.config.js only affects the other functions. So I'm trying to change the use of the other db in the code. In order to archive that I changed:

export const processVotes = functions.database.ref('/votes/{partyId}/{trackId}/{userId}') to
export const processVotes = functions.database.instance('my-second-db').ref('/votes/{partyId}/{trackId}/{userId}')

and I think it's a working approach because my log statements in this function are now executed. Sadly the next db accesses

const topmostTrack = firebase.database()
            .ref('/tracks')
            .child(partyId)
            .limitToFirst(1)
            .orderByChild('order')
            .once('value');

and

firebase.database()
        .ref('/tracks')
        .child(partyId)
        .child(trackId)
        .transaction(...)

are referring to the wrong db. I was assuming the firebase.database() statement is taking the database from the firebase.config.js. But in the google console logs I found:

[2022-06-20T21:18:01.066Z]  @firebase/database: FIREBASE WARNING: The Firebase database 'my-first-db-default-rtdb' has been disabled by a database owner. (https://my-first-db-default-rtdb.europe-west1.firebasedatabase.app/)

I don't know why only this functions want to use the old standard db and not the new one.

from app.

dnlkng avatar dnlkng commented on September 14, 2024

My final workaround is now overwriting the databaseURL in index.ts.

let config = JSON.parse(process.env.FIREBASE_CONFIG!);
// tslint:disable-next-line:no-var-requires
const serviceAccount = require('./service-account.json');

config["databaseURL"] = "https://my-second-db.firebaseio.com/";

firebase.initializeApp({
    ...config,
    credential: firebase.credential.cert(serviceAccount),
});

Obviously the line let config = JSON.parse(process.env.FIREBASE_CONFIG!); loads an outdated configuration file. But I don't find one in my workspace with the old value for the databaseURL. In my firebase.config.js the value for the key is correct. So for now, I have no issues with your awesome pice of software. Thank you very much, I will donate something.

from app.

itsmejoeeey avatar itsmejoeeey commented on September 14, 2024

Thanks for writing up your findings @dnlkng. Although I had the same symptoms as you (with a different cause), it still helped me towards finding my issue!

When looking in my functions console log I had something very similar to this StackOverflow thread:

TypeError: Cannot read property 'name' of undefined
    at dataConstructor (/workspace/node_modules/firebase-functions/lib/providers/database.js:137:85)
    at cloudFunctionNewSignature (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:119:34)
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
    at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:198:28)
    at process._tickCallback (internal/process/next_tick.js:68:7) 

In the end, the fix that worked for me was ensuring the following was set in functions/package.json:

  "engines": {
    "node": "16"
  }

And also updating firebase-functions and deps to latest:

cd functions
yarn upgrade firebase-functions@latest firebase-admin@latest typescript@latest
npm run deploy

Hope this helps anyone else who was in a similar boat to me.

from app.

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.