Giter Club home page Giter Club logo

Comments (5)

Jonas-Sander avatar Jonas-Sander commented on September 4, 2024

Is there something actionable we can do here really? Do you have information on why it might be missing?

from sharezone-app.

nilsreichardt avatar nilsreichardt commented on September 4, 2024

No, I don't have any idea, why this happen.

What we can do is catching the missing typeOfUser behaviour in the cloud function, which adds the user ids and check, if there are users without a typeOfUser. If yes, we notify ourselves via Slack. Advantage of this: Getting a feeling how many users are affected and getting the user ids of the affected users (they could give us more information, what they did before).

from sharezone-app.

Jonas-Sander avatar Jonas-Sander commented on September 4, 2024

@nilsreichardt Did you investigate this? Or is this still important? Just asking because this is still in "Soon-ish" in the triage board.

from sharezone-app.

nilsreichardt avatar nilsreichardt commented on September 4, 2024

I was reproducible with one of the versions before the summer (by using Google or Apple Sign In with an account that is not registered) but was fixed with one the updates in the summer. However, we should still do the following tasks:

  • Check if there are still broken documents even after the new updates (making a query that check the user documents of the last weeks)
  • Write a script that fixes the broken user documents (just using some default values because with a broken user document some features are not working like renaming)

from sharezone-app.

nilsreichardt avatar nilsreichardt commented on September 4, 2024

TL;DR

This issue appears to have been resolved. The last user with a broken user document created their account on 2023-10-31. Additionally, I have fixed all broken user documents that were in our database.

Here is the documentation of how I did it:

Because we can't query for documents without a field, I exported the User collection using:

PROJECT_ID="sharezone-c2bd8"
gcloud firestore export gs://$PROJECT_ID.appspot.com/export/2024-02-27-users \
    --collection-ids=User \
    --project=$PROJECT_ID

Then I imported the data to BigQuery using the following instructions: https://cloud.google.com/bigquery/docs/loading-data-cloud-firestore#console

I used the following SQL query to get all affected users:

SELECT __key__.name as UserId, createdOn, typeOfUser
FROM `sharezone-c2bd8.2024_02_27_User.User`
WHERE typeOfUser IS NULL
ORDER BY createdOn DESC

The number of affected users is 2251.

I exported the SQL query result as JSON and executed the following script:

import * as fs from "fs";
import { firestore } from "../firebase_globals";

async function main() {
  // Read users from JSON file
  const data = fs.readFileSync(`${__dirname}/data.json`).toString();
  const json = JSON.parse(data);
  let counter = 0;

  for (const user of json) {
    // Update user in Firestore
    await firestore.doc(`User/${user.UserId}`).update({
      typeOfUser: "student", // assuming that every affacted user is a student
    });

    // Log the action
    const logMessage = `Updated user ${user.UserId} to typeOfUser "student"`;
    fs.appendFileSync("log.txt", `${logMessage}\n`);
    console.log(`${logMessage}; ${++counter} users updated`);
  }
}

main().catch(console.error);

It's enough to only set the typeOfUser. Some cloud functions require a typeOfUser, like the UserUpdate cloud function. The other fields (name, etc.) can be easily changed by the user in the settings.

from sharezone-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.