Festify/app

Vote count not updated

Closed this issue · 5 comments

I'm successful running a version of festify on my firebase account. When hitting the like Button on a client (joined party mode), it immediately went to a filled heart icon. In addition the firebase realtime database inserts the changes for the entities votes and votes_by_user but not the field vote_count in the entity tracks. And the new order is not adopted accordingly to the new count of the votes. There are also zero votes TV mode view.

As I'm writing this I realise, that it behaves the same, when adding a single song to the queue.

I don't know if the app on https://festify.rocks is on the same commit as I am, but there I have no issues.

I appreciate every help, since I would like to use this awesome web app for my wedding in a few days.

Thank you
Daniel

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.

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).

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.

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.

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.