-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove user.id
use and rework vote logic
#401
Conversation
user.id
useuser.id
use and rework vote
logic
user.id
use and rework vote
logicuser.id
use and rework vote logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments to understand the changes. There are other minor changes throughout this PR which are self-explanatory.
routes/_404.tsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing-by changes.
routes/_500.tsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing-by changes.
await Promise.all(promises1); | ||
|
||
// Items | ||
const promises2 = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both arrays of promises, promises1
and promises2
, must resolve sequentially. Vote migrations cover all items that have votes. Item migrations cover all remaining items that have no votes.
Using Promise.all()
is optimal for performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: voted_items_by_user
and voted_users_by_item
indexes should be deleted once this PR is merged, as they are no longer used.
const [creatorUserRes, voterUserRes] = await kv.getMany<OldUser[]>([ | ||
["users", oldItem.userId], | ||
["users", voterUserId], | ||
]); | ||
assertIsEntry(creatorUserRes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The distinction between these two types of users must remain correct throughout this function.
if (!res.ok) throw new Error(`Failed to set vote: ${vote}`); | ||
} | ||
|
||
async function migrateItem(oldItem: OldItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is run after migrateVote()
and only takes care of those items with no votes.
thank you for providing the comments alongside the changes, which helped a lot in understanding the broader context. i was able to get through the steps w/o any issues. however i've noticed the following:
i will also do a more thorough review of the code changes but wanted to drop a note about my findings asap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran migration on prod KV snapshot successfully and updated DB seems working without problem. LGTM
@iuioiua thanks for the update! just tested the functionality from resetting to seeding to voting and migrating. |
I think the |
Vote logic was challenging to deal with, hence the rework. The most involved part of this PR is the migration script. In summary:
Reviews, please pay close attention to the migration script. It aims to preserve item, vote and user data. This script has worked multiple times on my local machine, but I still want it checked carefully. To test:
deno task db:reset
and thendeno task db:seed
.deno task start
, sign in, vote and comment on random items, noting the changes.deno run -A --unstable tools/migrate_kv.ts
.deno task start
and ensure all data is preserved.Please review, if willing and able, @brunocorrea23 and @mbhrznr.
Closes #400