TASVideos / tasvideos

The code for the live TASVideos website
https://tasvideos.org/
GNU General Public License v3.0
62 stars 29 forks source link

Show Username on Log Page #1735

Closed Masterjun3 closed 6 months ago

Masterjun3 commented 6 months ago

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