Giter Site home page Giter Site logo

Credits support about globalping HOT 7 CLOSED

MartinKolarik avatar MartinKolarik commented on August 27, 2024
Credits support

from globalping.

Comments (7)

alexey-yarmosh avatar alexey-yarmosh commented on August 27, 2024

Insert to credits_additions may happen even when associated users are not registered. Since they don't have userId it is not possible create a row in credits for them. That means users can't get credits for their donations/adoptions before they are registered on dashboard.

I can add a e.g. consumed: false column to credits_additions and set it to true only if value was added to credits. Then, on user sign up it is possible to go through all additions and give them all their prev credits.

from globalping.

MartinKolarik avatar MartinKolarik commented on August 27, 2024

That seems nice, sure. So when you start sponsoring and register only sometime later, you'll get all the credits.

from globalping.

alexey-yarmosh avatar alexey-yarmosh commented on August 27, 2024

Should X-RateLimit-Limit return values as previously? Or include available credits data?

from globalping.

MartinKolarik avatar MartinKolarik commented on August 27, 2024

Existing headers as before and this:

When credits are involved in handling the request, it would be good to also add two new headers: X-Credits-Remaining and X-Credits-Cost

from globalping.

alexey-yarmosh avatar alexey-yarmosh commented on August 27, 2024

Oh, missed that description part.

  • X-Credits-Cost is how much credits where deducted during that request?
  • seems like a second sql request is required to support X-Credits-Remaining, as update only returns number of affected rows:
await this.sql(CREDITS_TABLE).where({ user_id: userId }).update({ amount: this.sql.raw('amount - ?', [ credits ]) });
const remaining = await this.sql(CREDITS_TABLE).where({ user_id: userId }).select('amount');

there is an option to add add .returning('amount');, but that requires Postgresql.

const remaining = await this.sql(CREDITS_TABLE).where({ user_id: userId }).update({ amount: this.sql.raw('amount - ?', [ credits ]) }).returning('amount');

from globalping.

MartinKolarik avatar MartinKolarik commented on August 27, 2024

Should be possible with our DB too now: https://mariadb.com/kb/en/insertreturning/

Maybe will need a raw query if knex doesn't know it yet.

from globalping.

alexey-yarmosh avatar alexey-yarmosh commented on August 27, 2024

We need to update gp_credits instead of inserting. Since there is no UPDATE...RETURNING it still looks doable with INSERT INTO ... ON DUPLICATE KEY UPDATE ... RETURNING, where insert does nothing (amount: 0) and subtraction logic is inside ON DUPLICATE KEY UPDATE.

from globalping.

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.