hedy icon indicating copy to clipboard operation
hedy copied to clipboard

[PERFORMANCE] Change users table structure to enable pagination and filtering

Open TiBiBa opened this issue 2 years ago • 5 comments

This PR is not for merging, only for review and than running once to make sure everything works.

TiBiBa avatar Jun 29 '22 10:06 TiBiBa

Since this PR is open for quite some time already, I will shamelessly leave my unsolicited review here.

The script does successfully add an 'epoch' property to every user. The requests are not paced, which means that we might get throttled by AWS if we have many users to update. There is no error handling, but the update is idempotent, so even if the script fails halfway through, you could just rerun it (at the expense of extra read and write operations). I did execute it against my AWS dynamo setup (which mirrors Hedy's) and it was successful.

Unfortunately, I don't have the context of why we are adding an 'epoch' property but perhaps this is something @rix0rrr can comment on.

boryanagoncharenko avatar Jul 21 '22 11:07 boryanagoncharenko

Hi @boryanagoncharenko! Thanks for checking this PR, I had already forgotten it existed. The goal of adding an epoch is to enable us pagination on the sort key timestamp without needing to filter on an additional index key. Sadly Dynamo doesn't support the statement "give me the last x programs, sorted by timestamp".

In this case we need to provide an index key as well, by giving all programs a dummy value op epoch: 1 we can call all programs with the index epoch: 1 (which is all programs in this case) and then use the timestamp as sort key. Enabling us to efficiently sort all programs for the /explore page.

TiBiBa avatar Jul 22 '22 09:07 TiBiBa

Looking into this we might also be able to use PartiQL, which is supported within the DynamoDB web interface. Following the documentation we might be able to use some UPDATE statement: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.update.html.

Maybe something like this?

UPDATE "hedy-alpha-users" 
SET epoch=1

TiBiBa avatar Jul 22 '22 09:07 TiBiBa

Looking into this we might also be able to use PartiQL, which is supported within the DynamoDB web interface. Following the documentation we might be able to use some UPDATE statement: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.update.html.

Maybe something like this?

UPDATE "hedy-alpha-users" 
SET epoch=1

Nevermind.... Schermafbeelding 2022-07-22 om 11 43 47

TiBiBa avatar Jul 22 '22 09:07 TiBiBa

@Felienne I think we can run this on the Alpha db if that's okay with you. Than after some extensive testing (and changing a few db calls on the admin side) we can run it again on the Beta db.

TiBiBa avatar Aug 16 '22 15:08 TiBiBa

Unfortunately PartiQL requires a WHERE so it will not do this ;(

image

rix0rrr avatar Aug 31 '22 17:08 rix0rrr

I ran this script. The PR can be closed.

rix0rrr avatar Sep 10 '22 11:09 rix0rrr