fix: TUVote inner join TUVoteInfo for "Last Votes by TU" listing

By implicitly joining, sqlalchemy joined on
`TUVote.UsersID = TUVoteInfo.SubmitterID`. This should be joining on
`TUVote.VoteID = TUVoteInfo.ID` instead to include all TUVote instances
found in the database.

Closes #266

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-02-07 18:03:43 -08:00
parent 957803a70b
commit 660d57340a
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 28 additions and 12 deletions

View file

@ -81,17 +81,18 @@ async def trusted_user(request: Request,
context["past_off"] = past_off
last_vote = func.max(models.TUVote.VoteID).label("LastVote")
last_votes_by_tu = db.query(models.TUVote).join(
models.User
).join(models.TUVoteInfo).filter(
last_votes_by_tu = db.query(models.TUVote).join(models.User).join(
models.TUVoteInfo,
models.TUVoteInfo.ID == models.TUVote.VoteID
).filter(
and_(models.TUVote.VoteID == models.TUVoteInfo.ID,
models.User.ID == models.TUVote.UserID,
models.TUVoteInfo.End <= ts,
models.TUVoteInfo.End < ts,
or_(models.User.AccountTypeID == 2,
models.User.AccountTypeID == 4))
).with_entities(
models.TUVote.UserID,
func.max(models.TUVote.VoteID).label("LastVote"),
last_vote,
models.User.Username
).group_by(models.TUVote.UserID).order_by(
last_vote.desc(), models.User.Username.asc())