-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c819c8e
commit 91108f5
Showing
10 changed files
with
118 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
supabase/migrations/20231029115759_fixLeaderboardAuthor.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
|
||
CREATE OR REPLACE FUNCTION get_leaderboard(userid uuid, _unit event_units, datestart timestamp DEFAULT '2020-01-01 00:00:00+00', dateend timestamp with time zone DEFAULT NOW()) | ||
RETURNS TABLE ( | ||
user_id uuid, | ||
username character varying, | ||
old_usernames character varying[], | ||
win real, | ||
lost real, | ||
score real | ||
) | ||
LANGUAGE plpgsql AS | ||
$func$ | ||
BEGIN | ||
return query | ||
SELECT p.*, COALESCE(SUM(rW.number) ,0) as win, COALESCE(SUM(rL.number),0) as lost, COALESCE(SUM(rW.number),0) - COALESCE(SUM(rL.number) ,0) as score | ||
FROM profiles p | ||
right JOIN events_users_participation eup1 ON eup1.user_id = p.user_id | ||
LEFT JOIN results rW ON rW.to_id = p.user_id | ||
LEFT JOIN results rL ON rL.from_id = p.user_id | ||
WHERE | ||
p.user_id != userid AND | ||
( -- participant | ||
eup1.event_code IN ( | ||
select eup.event_code | ||
from events_users_participation eup, events e | ||
WHERE eup.user_id = userid | ||
AND e.invite_code = eup.event_code | ||
AND e.date_finish BETWEEN dateStart AND dateEnd | ||
AND e.unit = _unit | ||
) | ||
OR -- author | ||
eup1.event_code IN ( | ||
select e.invite_code | ||
from events e | ||
where e.author = userid | ||
AND e.date_finish BETWEEN dateStart AND dateEnd | ||
AND e.unit = _unit | ||
) | ||
) | ||
group by p.user_id | ||
order by score DESC; | ||
END | ||
$func$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters