Giter Site home page Giter Site logo

bobaboard / boba-backend Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 12.0 4.06 MB

BobaBoard's Backend

Home Page: https://www.bobaboard.com

License: MIT License

TypeScript 98.91% Dockerfile 0.13% Shell 0.25% JavaScript 0.09% Handlebars 0.33% Nix 0.30%
bobaboard

boba-backend's People

Contributors

akrobi avatar antenetica avatar dependabot[bot] avatar enigmalea avatar essential-randomness avatar featherbutt avatar mindthespines avatar msmadgirl avatar reptapog avatar siotle avatar virtuous-cat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boba-backend's Issues

Standardize variable names in server code

This is a catch-all bug for standardizing variable names in the server (feel free to propose more changes, and create an appropriate bug for each change as you decide to work on it/feel like doing some filing work):

  • Make all string IDs specifically named thingStringId.

Prototype using Zod to add type safety to database queries

Zod is a library that allows us to define and validate the shape of a JavaScript object and automatically generates the corresponding TypeScript types.

We want to create Zod types for all the SELECT queries in our database to provide strong typings to the data coming out of the database.

Add default realm member permissions to DB

  • add realm permissions to DB and permissions.ts: post_on_realm, comment_on_realm, create_thread_on_realm, access_locked_boards_on_realm
  • create REALM_MEMBER_PERMISSIONS array

Allow associating a user with (one or more) realms

Add realm_users table with:

  • user_id (referencing table users)
  • realm_id (referencing table realms)

Unique index on realm_id, user_id (there shouldn't be more than one entry where both of these are the same)

Remove fetching of Realm notifications from `/realms/slug/{realm_name}` endpoint

Problem

Fetching of Realm notifications is really slow and needs to be redesigned. Luckily, we already did some work splitting the "realm data fetching" endpoint (/realms/slug/{realm_name}) and the "realm notifications" endpoint (/realms/{realm_id}/notifications). However, the data fetching endpoint still uses the query that also fetches notifications, which is less than ideal.

Let's fix that!

The Players

  • getRealmBoards is our entry point into the infamous "white whale query", the worst performing boba query that we have declared unfixable.
  • This function is used in all realm data fetching queries, even the ones that don't need notifications.
  • Likely, this wasn't changed even when I split the two endpoints cause I didn't want to redo the tests. I suspect that's going to be the "PITA" part of this fix.

Step by Step

  • Zod the getRealmBoards query as data comes out of the database
  • Zod the /realms/slug/{realm_name} endpoint
  • Zod the /realms/{realm_id}/notifications endpoint
  • Create a new (immediately-zodded) database query that gets all the boards in the realm with only the data effectively needed by the /realms/slug/{realm_name} endpoint
  • Switch out the /realms/slug/{realm_name} endpoint to use that query
  • Fix all tests (sorry)

Stretch

  • Figure out if the getRealmBoards query is used in other parts of the codebase that don't need it.

The Future

While this gets fixed we'll be working on improving the performance of the notifications query by leveraging Redis.

Move responsibility for assembling invite URLs from the server to the client

The server should only return the invite code and let the client construct the invite URL. If we don't do this, then we leak info that the client is in charge of to the server.

Endpoints to be updated:

Add additional Users routes to improve RESTfulness

  • Move the /realms/{realm_id}/notifications endpoint to users/@me/notifications/realms/{realm_id}
  • Create an endpoint users/@me/permissions/realms/{realm_id} and have it return the user's realm permissions instead of /realm/{realm_slug}

Update server to check member realm permissions

  • update getUserPermissionsForRealm query to check that user is a member of the realm and append default realm member permissions
  • update ensureBoardAccess handler to check for accessLockedBoardOnRealm permission
  • update open-api permissions schema RealmPermissions enum
  • gate logged in routes as appropriate with ensureRealmPermission (will have to include realm_id in req for any gated route, or extract it from existing info)
  • update tests

Allow get invites endpoint to return all invites filtered by status

[Currently the get /realms/realm_id/invites/ endpoint is setup to only return the pending invites for the realm.]

The "right" way of doing it would be to return all the invites (with pagination), then have a status get param which allows to filter by status. For example, our request could be:

/realms/v0/invites?status=PENDING

to only get the pending invites.

Two things that I didn't add in the design that prevents us from doing this the right way:

  1. We don't have a status enum we return with the invite. This is because I thought we'd just calculate it with expired_at and didn't want to duplicate the information, but I was wrong. We should have a status field which has at least: PENDING, ACCEPTED, EXPIRED (potentially for the future REVOKED).
  2. We don't have pagination for this endpoint, which is not a huge deal for now if we're returning only pending invites, but will be at some point in the future.

Originally posted by @essential-randomness in #53 (comment)

Add ability to control rate of new user account creation

Currently all Realm invites have the potential to create a new user account.

Before the implementation of additional Realms beyond Fandom Coders, we need the ability to control how many new Boba users a given Realm's leadership team has the ability to create in a given time period. Possible options for the design of this mentioned so far include:

a) Splitting off sign-up invites from Realm invites entirely and giving them separate endpoints.
or
b) Simply adding a boolean to check whether an invite has the power to create an account in the invites table

Some previous history of this issue can be found here: #46

Further consideration of the design of the invite flow is required to resolve this issue.

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.