From 2ae9d2a4c193c2da0f49b17860283aae3a168fac Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 30 Oct 2022 14:46:32 +1300 Subject: [PATCH] Improve performance of StartPlan --- StartPlan.tsx | 6 +----- set.service.ts | 11 +++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/StartPlan.tsx b/StartPlan.tsx index 6b16e74..140a2c1 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -144,11 +144,7 @@ export default function StartPlan() { renderItem={({item, index}) => ( select(index)} left={() => ( => { }; export const countMany = async (names: string[]): Promise => { - const questions = names.map(_ => '?').join(','); + const questions = names.map(_ => '(?)').join(','); console.log({questions, names}); const select = ` SELECT workouts.name, COUNT(sets.id) as total - FROM ( - SELECT distinct name FROM sets - WHERE name IN (${questions}) - ) workouts + FROM (select 0 as name union values ${questions}) as workouts LEFT JOIN sets ON sets.name = workouts.name AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime') AND NOT sets.hidden - GROUP BY workouts.name; + GROUP BY workouts.name + LIMIT -1 + OFFSET 1 `; const [result] = await db.executeSql(select, names); return result.rows.raw();