From b844af8080da6aa0ad0e8eb8ee5daf91aa5173ee Mon Sep 17 00:00:00 2001 From: Chris Rodrigues Date: Thu, 9 Jan 2025 12:38:17 -0800 Subject: [PATCH 1/2] fix(smf-query): Replaced posterName field with realName from joined smf_members table --- lib/epochtalk_server/smf_query.ex | 48 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/epochtalk_server/smf_query.ex b/lib/epochtalk_server/smf_query.ex index cbfcd1e2..9b909f68 100644 --- a/lib/epochtalk_server/smf_query.ex +++ b/lib/epochtalk_server/smf_query.ex @@ -113,10 +113,11 @@ defmodule EpochtalkServer.SmfQuery do where: t.id_board not in ^id_board_blacklist, order_by: [desc: t.id_last_msg] ) - |> join(:left, [t], m in "smf_messages", on: t.id_first_msg == m.id_msg) - |> join(:left, [t], m in "smf_messages", on: t.id_last_msg == m.id_msg) - |> join(:left, [t], b in "smf_boards", on: t.id_board == b.id_board) - |> select([t, f, l, b], %{ + |> join(:left, [t], f in "smf_messages", on: t.id_first_msg == f.id_msg) + |> join(:left, [t, f], l in "smf_messages", on: t.id_last_msg == l.id_msg) + |> join(:left, [t, f, l], m in "smf_members", on: l.id_member == m.id_member) + |> join(:left, [t, f, l, m], b in "smf_boards", on: t.id_board == b.id_board) + |> select([t, f, l, m, b], %{ id: t.id_topic, slug: t.id_topic, board_id: t.id_board, @@ -132,7 +133,7 @@ defmodule EpochtalkServer.SmfQuery do updated_at: l.posterTime * @ms_per_sec, last_post_created_at: l.posterTime * @ms_per_sec, last_post_user_id: l.id_member, - last_post_username: l.posterName, + last_post_username: m.realName, view_count: t.numViews, last_post_position: nil, last_post_deleted: false, @@ -209,7 +210,7 @@ defmodule EpochtalkServer.SmfQuery do id: b.id_board, last_post_created_at: m.posterTime * @ms_per_sec, last_post_position: t.numReplies, - last_post_username: m.posterName, + last_post_username: u.realName, last_post_user_id: m.id_member, last_post_avatar: fragment( @@ -306,12 +307,13 @@ defmodule EpochtalkServer.SmfQuery do order_by: [desc: t.id_last_msg] ) |> join(:left, [t], f in "smf_messages", on: t.id_first_msg == f.id_msg) - |> join(:left, [t], l in "smf_messages", on: t.id_last_msg == l.id_msg) - |> join(:left, [t, f, l], m in "smf_members", on: l.id_member == m.id_member) - |> join(:left, [t, f, l, m], a in "smf_attachments", - on: m.id_member == a.id_member and a.attachmentType == 1 + |> join(:left, [t, f], fm in "smf_members", on: f.id_member == fm.id_member) + |> join(:left, [t, f, fm], l in "smf_messages", on: t.id_last_msg == l.id_msg) + |> join(:left, [t, f, fm, l], lm in "smf_members", on: l.id_member == lm.id_member) + |> join(:left, [t, f, fm, l, lm], a in "smf_attachments", + on: lm.id_member == a.id_member and a.attachmentType == 1 ) - |> select([t, f, l, m, a], %{ + |> select([t, f, fm, l, lm, a], %{ id: t.id_topic, slug: t.id_topic, board_id: t.id_board, @@ -326,19 +328,19 @@ defmodule EpochtalkServer.SmfQuery do post_count: t.numReplies, title: f.subject, user_id: f.id_member, - username: f.posterName, + username: fm.realName, created_at: f.posterTime * @ms_per_sec, user_deleted: false, last_post_created_at: l.posterTime * @ms_per_sec, last_post_deleted: false, last_post_user_id: l.id_member, - last_post_username: l.posterName, + last_post_username: lm.realName, last_post_user_deleted: false, last_post_avatar: fragment( "if(? <>'',concat('https://bitcointalk.org/avatars/',?),ifnull(concat('https://bitcointalk.org/useravatars/',?),''))", - m.avatar, - m.avatar, + lm.avatar, + lm.avatar, a.filename ), last_viewed: nil, @@ -355,9 +357,11 @@ defmodule EpochtalkServer.SmfQuery do where: t.id_topic == ^id and t.id_board not in ^id_board_blacklist ) # get first and last message for thread - |> join(:left, [t], m in "smf_messages", on: t.id_first_msg == m.id_msg) - |> join(:left, [t], m in "smf_messages", on: t.id_last_msg == m.id_msg) - |> select([t, f, l], %{ + |> join(:left, [t], f in "smf_messages", on: t.id_first_msg == f.id_msg) + |> join(:left, [t, f], fm in "smf_members", on: f.id_member == fm.id_member) + |> join(:left, [t, f, fm], l in "smf_messages", on: t.id_last_msg == l.id_msg) + |> join(:left, [t, f, fm, l], lm in "smf_members", on: l.id_member == lm.id_member) + |> select([t, f, fm, l, lm], %{ id: t.id_topic, slug: t.id_topic, board_id: t.id_board, @@ -372,13 +376,13 @@ defmodule EpochtalkServer.SmfQuery do post_count: t.numReplies, title: f.subject, user_id: f.id_member, - username: f.posterName, + username: fm.realName, created_at: f.posterTime * @ms_per_sec, user_deleted: false, last_post_created_at: l.posterTime * @ms_per_sec, last_post_deleted: false, last_post_user_id: l.id_member, - last_post_username: l.posterName, + last_post_username: lm.realName, last_post_user_deleted: false, last_viewed: nil }) @@ -448,7 +452,7 @@ defmodule EpochtalkServer.SmfQuery do title: m.subject, body: m.body, updated_at: m.modifiedTime, - username: m.posterName, + username: m.realName, created_at: m.posterTime * @ms_per_sec, modified_time: m.modifiedTime, avatar: @@ -460,7 +464,7 @@ defmodule EpochtalkServer.SmfQuery do ), user: %{ id: m.id_member, - username: m.posterName, + username: m.realName, signature: u.signature, activity: u.activity, merit: u.merit, From 78d83b2a6b6d583dbf89f0225e9669866bc4812e Mon Sep 17 00:00:00 2001 From: Chris Rodrigues Date: Thu, 9 Jan 2025 12:48:48 -0800 Subject: [PATCH 2/2] fix(smf_query): Fixing naming errors with new smf_members join --- lib/epochtalk_server/smf_query.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/epochtalk_server/smf_query.ex b/lib/epochtalk_server/smf_query.ex index 9b909f68..f3a848ae 100644 --- a/lib/epochtalk_server/smf_query.ex +++ b/lib/epochtalk_server/smf_query.ex @@ -115,9 +115,9 @@ defmodule EpochtalkServer.SmfQuery do ) |> join(:left, [t], f in "smf_messages", on: t.id_first_msg == f.id_msg) |> join(:left, [t, f], l in "smf_messages", on: t.id_last_msg == l.id_msg) - |> join(:left, [t, f, l], m in "smf_members", on: l.id_member == m.id_member) - |> join(:left, [t, f, l, m], b in "smf_boards", on: t.id_board == b.id_board) - |> select([t, f, l, m, b], %{ + |> join(:left, [t, f, l], lm in "smf_members", on: l.id_member == lm.id_member) + |> join(:left, [t, f, l, lm], b in "smf_boards", on: t.id_board == b.id_board) + |> select([t, f, l, lm, b], %{ id: t.id_topic, slug: t.id_topic, board_id: t.id_board, @@ -133,7 +133,7 @@ defmodule EpochtalkServer.SmfQuery do updated_at: l.posterTime * @ms_per_sec, last_post_created_at: l.posterTime * @ms_per_sec, last_post_user_id: l.id_member, - last_post_username: m.realName, + last_post_username: lm.realName, view_count: t.numViews, last_post_position: nil, last_post_deleted: false, @@ -452,7 +452,7 @@ defmodule EpochtalkServer.SmfQuery do title: m.subject, body: m.body, updated_at: m.modifiedTime, - username: m.realName, + username: u.realName, created_at: m.posterTime * @ms_per_sec, modified_time: m.modifiedTime, avatar: @@ -464,7 +464,7 @@ defmodule EpochtalkServer.SmfQuery do ), user: %{ id: m.id_member, - username: m.realName, + username: u.realName, signature: u.signature, activity: u.activity, merit: u.merit,