From f1a8277c22fa8d7f1c64ad685a26ee65164f7c60 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 9 Nov 2020 06:30:20 -0800 Subject: [PATCH] simplify offering/seeking count query --- src/server/loaders.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/server/loaders.js b/src/server/loaders.js index 9982efd..b40dab5 100644 --- a/src/server/loaders.js +++ b/src/server/loaders.js @@ -400,10 +400,9 @@ const buildItemTradeCountsLoader = (db) => const [rows, _] = await db.execute( ` SELECT - items.id AS item_id, closet_hangers.owned AS is_owned, + closet_hangers.item_id AS item_id, closet_hangers.owned AS is_owned, count(DISTINCT closet_hangers.user_id) AS users_count - FROM items - INNER JOIN closet_hangers ON closet_hangers.item_id = items.id + FROM closet_hangers INNER JOIN users ON users.id = closet_hangers.user_id LEFT JOIN closet_lists ON closet_lists.id = closet_hangers.list_id WHERE ( @@ -420,7 +419,7 @@ const buildItemTradeCountsLoader = (db) => ) ) ) - GROUP BY items.id, closet_hangers.owned; + GROUP BY closet_hangers.item_id, closet_hangers.owned; `, values );