rhythia-api 242.0.0 → 243.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,47 @@
1
- CREATE OR REPLACE FUNCTION public.get_top_scores_for_beatmap3(beatmap_hash text)
2
- RETURNS TABLE(id bigint, awarded_sp numeric, created_at timestamp without time zone, misses integer, mods json, passed boolean, "replayHwid" text, "songId" text, speed numeric, spin boolean, "userId" bigint, username text, avatar_url text, accuracy numeric)
3
- LANGUAGE sql
4
- STABLE
5
- AS $function$
6
- WITH bm AS (
7
- SELECT "noteCount"
8
- FROM beatmaps
9
- WHERE "beatmapHash" = beatmap_hash
10
- )
11
- SELECT
12
- s.id,
13
- s.awarded_sp,
14
- s.created_at,
15
- s.misses,
16
- s.mods,
17
- s.passed,
18
- s."replayHwid",
19
- s."songId",
20
- s.speed,
21
- s.spin,
22
- s."userId",
23
- p.username,
24
- p.avatar_url,
25
- CASE
26
- WHEN bm."noteCount" > 0 THEN
27
- ROUND(((bm."noteCount" - s.misses) / bm."noteCount" * 100)::numeric, 2)
28
- ELSE 0
29
- END AS accuracy
30
- FROM leaderboard_map_user l
31
- JOIN scores s ON s.id = l.best_score_id
32
- JOIN profiles p ON s."userId" = p.id
33
- CROSS JOIN bm
34
- WHERE l."beatmapHash" = beatmap_hash
35
- AND p.ban <> 'excluded'
36
- ORDER BY l.best_sp DESC
37
- LIMIT 10;
38
- $function$
1
+ DROP FUNCTION IF EXISTS public.get_top_scores_for_beatmap3(beatmap_hash text);
2
+
3
+ CREATE OR REPLACE FUNCTION public.get_top_scores_for_beatmap3(beatmap_hash text, score_limit integer DEFAULT 50)
4
+ RETURNS TABLE(id bigint, awarded_sp numeric, created_at timestamp without time zone, misses integer, mods json, passed boolean, "replayHwid" text, "songId" text, speed numeric, spin boolean, "userId" bigint, username text, avatar_url text, accuracy numeric)
5
+ LANGUAGE sql
6
+ STABLE
7
+ AS $function$
8
+ WITH bm AS (
9
+ SELECT "noteCount"
10
+ FROM beatmaps
11
+ WHERE "beatmapHash" = beatmap_hash
12
+ )
13
+ SELECT
14
+ s.id,
15
+ s.awarded_sp,
16
+ s.created_at,
17
+ s.misses,
18
+ s.mods,
19
+ s.passed,
20
+ s."replayHwid",
21
+ s."songId",
22
+ s.speed,
23
+ s.spin,
24
+ s."userId",
25
+ p.username,
26
+ p.avatar_url,
27
+ CASE
28
+ WHEN bm."noteCount" > 0 THEN
29
+ ROUND(((bm."noteCount" - s.misses) / bm."noteCount" * 100)::numeric, 2)
30
+ ELSE 0
31
+ END AS accuracy
32
+ FROM leaderboard_map_user l
33
+ JOIN scores s ON s.id = l.best_score_id
34
+ JOIN profiles p ON s."userId" = p.id
35
+ CROSS JOIN bm
36
+ WHERE l."beatmapHash" = beatmap_hash
37
+ AND s.passed = true
38
+ AND p.ban <> 'excluded'
39
+ AND EXISTS (
40
+ SELECT 1
41
+ FROM scores recent
42
+ WHERE recent."userId" = s."userId"
43
+ AND recent.created_at >= now() - interval '30 days'
44
+ )
45
+ ORDER BY l.best_sp DESC
46
+ LIMIT LEAST(GREATEST(COALESCE(score_limit, 50), 1), 50);
47
+ $function$
@@ -0,0 +1,66 @@
1
+ CREATE OR REPLACE FUNCTION public.handle_profile_flag_change()
2
+ RETURNS trigger
3
+ LANGUAGE plpgsql
4
+ AS $function$
5
+ begin
6
+ if new.flag is not distinct from old.flag then
7
+ return new;
8
+ end if;
9
+
10
+ if current_setting('app.bypass_profile_limits', true) = 'on' then
11
+ return new;
12
+ end if;
13
+
14
+ if exists (
15
+ select 1
16
+ from public."profileFlags" pf
17
+ where pf.profile_id = old.id
18
+ ) then
19
+ raise exception 'Flag can only be changed once'
20
+ using errcode = 'P0001';
21
+ end if;
22
+
23
+ insert into public."profileFlags" (profile_id, flag, changed_at)
24
+ values (old.id, old.flag, now());
25
+
26
+ return new;
27
+ end;
28
+ $function$;
29
+
30
+ CREATE OR REPLACE FUNCTION public.handle_profile_username_change()
31
+ RETURNS trigger
32
+ LANGUAGE plpgsql
33
+ AS $function$
34
+ declare
35
+ latest_change_at timestamptz;
36
+ begin
37
+ if new.username is not distinct from old.username then
38
+ return new;
39
+ end if;
40
+
41
+ if current_setting('app.bypass_profile_limits', true) = 'on' then
42
+ return new;
43
+ end if;
44
+
45
+ select pu.changed_at
46
+ into latest_change_at
47
+ from public."profileUsernames" pu
48
+ where pu.profile_id = old.id
49
+ order by pu.changed_at desc
50
+ limit 1;
51
+
52
+ if latest_change_at is not null
53
+ and latest_change_at + interval '6 months' > now() then
54
+ raise exception 'Username can only be changed once every 6 months'
55
+ using errcode = 'P0001',
56
+ detail = 'next_username_change_at=' || (latest_change_at + interval '6 months');
57
+ end if;
58
+
59
+ if old.username is not null and btrim(old.username) <> '' then
60
+ insert into public."profileUsernames" (profile_id, username, changed_at)
61
+ values (old.id, old.username, now());
62
+ end if;
63
+
64
+ return new;
65
+ end;
66
+ $function$;