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

Show Username on Log Page #1735

Merged
merged 2 commits into from
Jan 14, 2024
Merged

Show Username on Log Page #1735

merged 2 commits into from
Jan 14, 2024

Conversation

Masterjun3
Copy link
Collaborator

Resolves #1584 .

Because these are logs, using EF Core directly for the relationship felt weird, because it would create foreign keys and we don't really want those.
So this solution implements a manual join. In fact, a LEFT JOIN, because we still want to show logs that have no fitting UserId set.

The Microsoft docs show how EF Core converts a "GroupJoin(), SelectMany(), DefaultIfEmpty()" combination into a LEFT JOIN.
And this works as expected (notice the LEFT JOIN):

[18:49:09 INF] Executed DbCommand (5ms) [Parameters=[@__Table_0='Games', @__rowStr_1='1', @__p_3='25', @__p_2='0'], CommandType='Text', CommandTimeout='30']
SELECT a.row_id AS "RowId", CASE
    WHEN (u.id IS NULL) THEN 'Unknown_User'
    ELSE u.user_name
END AS "UserName", a.created AS "Created", a.table_name AS "TableName", a.changed AS "Changed", a.kind AS "Kind"
FROM auto_history AS a
LEFT JOIN users AS u ON a.user_id = u.id
WHERE (a.table_name = @__Table_0) AND (a.row_id = @__rowStr_1)
ORDER BY a.created DESC
LIMIT @__p_3 OFFSET @__p_2

@Masterjun3 Masterjun3 requested a review from adelikat January 4, 2024 18:00
@adelikat adelikat merged commit a0a3cc4 into main Jan 14, 2024
1 check passed
@adelikat adelikat deleted the logs-display-usernames branch January 14, 2024 18:24
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 this pull request may close these issues.

Game history logs display UserId instead of User
2 participants