Skip to content
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

Take age into account when ranking questions #194

Closed
jonhoo opened this issue Dec 27, 2024 · 1 comment · Fixed by #195
Closed

Take age into account when ranking questions #194

jonhoo opened this issue Dec 27, 2024 · 1 comment · Fixed by #195

Comments

@jonhoo
Copy link
Owner

jonhoo commented Dec 27, 2024

A reasonable place to start is probably https://www.evanmiller.org/ranking-news-items-with-upvotes.html

Since we currently do sorting in the client

qs.sort((a, b) => {
return b.votes - a.votes;
});

and on the server (for local operation)

qs.sort_unstable_by_key(|qid| {
std::cmp::Reverse(
questions[qid]["votes"]
.as_n()
.expect("votes is always set")
.parse::<usize>()
.expect("votes are always numbers"),
)
});

and in DynamoDB (for prod operation)

.index_name("top")

this is going to have to be repeated in a few places. DynamoDB also can't have an index on this kind of computed property, so we'll want to sort after fetching the list from DynamoDB (which will let us unify sorting between local and prod). We'll also need to expose the time a question was asked in the non-key fields in the top index that we query from so that we get it back from the query to top:

non_key_attributes = ["answered", "hidden"]

@jonhoo
Copy link
Owner Author

jonhoo commented Dec 27, 2024

Why do we even sort in both places? Feels like we should be able to get rid of at least one.

Also, if the qid is a ULID, we can just grab the time out of that. Difference in minutes, rounded up, clamped to 1.. is probably fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant