Roulette bugging points lower #306

Open
AirbrushGrenade opened this Issue Jun 11, 2016 · 1 comment

Projects

None yet

2 participants

@AirbrushGrenade

http://imgur.com/a/qvatN

as you can see in the album, whenever i win a roulette i get dragged down in points a lot( for example 2016-06-08 17:42:57-17:43:30)
I had 42246 points, win 404 in roulette = 42650 points. !userpoints shows exactly 9000 points less (33650). This happened several times with different numbers and I didn't give anyone that many points(can't really get whisper logs to botnextdoor but atleast the ones in nymn's chat for that timespan)

Down total by now: 19980 points D:

@TranRed
TranRed commented Dec 19, 2016 edited

I came up with an idea how the issue can be solved, but you have to check if the solution is feasible in redis and pajbot in general.

DISCLAIMER:

I never worked with a key-value db, so idk if it is feasible this way => The following description is based on relational dbs.

Assumption:

I assume the points are now stored in the user "table" (key-value set).
{User (Key), points, column2 , ... column n }

Problem description:

I asuume the problem is the following sequence:
Original state: {TranRed, 100 ... }

  1. raffle entered (for 50 points)
  2. roullette all reads 100
  3. raffle won reads 100
  4. roulette all won -> update to 200 (100+100)
    New state: {TranRed, 200 ... }
  5. raffle won (for 50 points) -> update to 150 (100 +50)
    New state: {TranRed, 150 ... }

Solution proposal:

(again based solely on my knowledge about relational dbs)
I propose to create two new tables. One Snapshot table (stores point snapshots in a certain interval) and one delta table (stores points deltas)

Snapshot:
{ User (Foreign-Key), Timestamp (Key), Points }

Delta:
{ User (Foreign-Key), Timestamp (Key), PointsUdate }

Populated with our example:
Snapshot
{ TranRed, 2016-12-19 00:00:00, 97 }

Deltas:
{ TranRed, 2016-12-19 19:58:00, +1 } (gained one point for watching as sub)
{ TranRed, 2016-12-19 19:59:00, +1 } (gained one point for watching as sub)
{ TranRed, 2016-12-19 20:00:00, +1 } (gained one point for watching as sub)
{ TranRed, 2016-12-19 20:00:59, +100 } (roulette all won)
{ TranRed, 2016-12-19 21:00:00, +50 } (raffle won)

Reading the points would work like this:
lastSnapshotPoints (MAX(timestamp)) + sumOfNewDeltas ( SUM(PointsUpdate) WHERE timestamp GT snapshot.timestamp ) => 97 + 153 = 250

Open questions:

  1. How often should snapshots be created? (daily, hourly)
  2. When will "old data" be deleted? I would delete everything that is older than the last 2 or 3 snapshots to save "diskspace"
  3. How to avoid the same race condition while writing the snapshot? Proposal: Start the new snapshot creation for 00:00:00 a few minutes later (e.g. 00:05:00) but restrict the selection of the deltas to the timestamp date (BETWEEN lastTimestamp AND newSnapshotTimestamp )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment