Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 6673460

Browse files
committed
Merge pull request #380 from Ghost141/dev
TC API - Pratice Problems API - Query Improvement
2 parents 03a39f3 + d071f73 commit 6673460

9 files changed

+45
-123
lines changed

queries/get_practice_problems

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
SELECT
22
SKIP @firstRowIndex@
33
FIRST @pageSize@
4-
*
4+
*
55
FROM table(MULTISET(
66
SELECT
77
p.problem_id
8-
, c.component_id
8+
, c.component_id
99
, ro.room_id
1010
, rc.round_id
1111
, rc.division_id
@@ -16,63 +16,18 @@ SELECT
1616
WHEN (p.problem_type_id = 1 AND p.proposed_difficulty_id = 3) THEN 'Hard'::nvarchar(50)
1717
END AS difficulty
1818
, rc.points
19-
, NVL(CASE WHEN EXISTS (
20-
SELECT 1
21-
FROM component_state cs
22-
WHERE cs.status_id < 120
23-
AND cs.component_id = c.component_id
24-
AND cs.coder_id = @userId@
25-
UNION ALL
26-
SELECT 1
27-
FROM practice_component_state pcs
28-
WHERE pcs.status_id < 120
29-
AND pcs.component_id = c.component_id
30-
AND pcs.coder_id = @userId@
31-
) THEN 'New'::nvarchar(50)
32-
WHEN EXISTS (
33-
SELECT 1
34-
FROM component_state cs
35-
WHERE cs.status_id = 150
36-
AND cs.component_id = c.component_id
37-
AND cs.coder_id = @userId@
38-
UNION ALL
39-
SELECT 1
40-
FROM practice_component_state pcs
41-
WHERE pcs.status_id = 150
42-
AND pcs.component_id = c.component_id
43-
AND pcs.coder_id = @userId@
44-
) THEN 'Solved'::nvarchar(50)
45-
WHEN EXISTS (
46-
SELECT 1
47-
FROM component_state cs
48-
WHERE cs.status_id >= 120
49-
AND cs.component_id = c.component_id
50-
AND cs.status_id != 150
51-
AND cs.coder_id = @userId@
52-
UNION ALL
53-
SELECT 1
54-
FROM practice_component_state pcs
55-
WHERE pcs.status_id >= 120
56-
AND pcs.component_id = c.component_id
57-
AND pcs.status_id != 150
58-
AND pcs.coder_id = @userId@
59-
) THEN 'Viewed'::nvarchar(50)
60-
END, 'New') AS status
61-
, NVL((
62-
SELECT
63-
points
64-
FROM practice_component_state pcs
65-
WHERE pcs.round_id = rc.round_id
66-
AND pcs.component_id = c.component_id
67-
AND pcs.coder_id = @userId@
68-
), 0) AS my_points
19+
, NVL( CASE WHEN pcs.status_id < 120 THEN 'New'::nvarchar(50)
20+
WHEN pcs.status_id = 150 THEN 'Solved'::nvarchar(50)
21+
WHEN pcs.status_id >= 120 AND pcs.status_id != 150 THEN 'Viewed'::nvarchar(50)
22+
END, 'New') AS status
23+
, NVL(pcs.points, 0) AS my_points
6924
FROM problem p
25+
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
7026
INNER JOIN component c ON c.problem_id = p.problem_id
7127
INNER JOIN round_component rc ON rc.component_id = c.component_id
7228
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A' AND r.round_type_id = 3
7329
INNER JOIN room ro ON ro.round_id = rc.round_id AND ro.room_type_id = 3 -- practice room
74-
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
75-
WHERE p.status_id = 90
30+
LEFT JOIN practice_component_state pcs ON pcs.round_id = rc.round_id AND pcs.component_id = c.component_id AND pcs.coder_id = @userId@
7631
)) srp
7732
WHERE 1=1
7833
ORDER BY @sortColumn@ @sortOrder@

queries/get_practice_problems_count

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,17 @@ SELECT
1313
WHEN (p.problem_type_id = 1 AND p.proposed_difficulty_id = 3) THEN 'Hard'::nvarchar(50)
1414
END AS difficulty
1515
, rc.points
16-
, NVL(CASE WHEN EXISTS (
17-
SELECT 1
18-
FROM component_state cs
19-
WHERE cs.status_id < 120
20-
AND cs.component_id = c.component_id
21-
AND cs.coder_id = @userId@
22-
UNION ALL
23-
SELECT 1
24-
FROM practice_component_state pcs
25-
WHERE pcs.status_id < 120
26-
AND pcs.component_id = c.component_id
27-
AND pcs.coder_id = @userId@
28-
) THEN 'New'::nvarchar(50)
29-
WHEN EXISTS (
30-
SELECT 1
31-
FROM component_state cs
32-
WHERE cs.status_id = 150
33-
AND cs.component_id = c.component_id
34-
AND cs.coder_id = @userId@
35-
UNION ALL
36-
SELECT 1
37-
FROM practice_component_state pcs
38-
WHERE pcs.status_id = 150
39-
AND pcs.component_id = c.component_id
40-
AND pcs.coder_id = @userId@
41-
) THEN 'Solved'::nvarchar(50)
42-
WHEN EXISTS (
43-
SELECT 1
44-
FROM component_state cs
45-
WHERE cs.status_id >= 120
46-
AND cs.component_id = c.component_id
47-
AND cs.status_id != 150
48-
AND cs.coder_id = @userId@
49-
UNION ALL
50-
SELECT 1
51-
FROM practice_component_state pcs
52-
WHERE pcs.status_id >= 120
53-
AND pcs.component_id = c.component_id
54-
AND pcs.status_id != 150
55-
AND pcs.coder_id = @userId@
56-
) THEN 'Viewed'::nvarchar(50)
57-
END, 'New') AS status
58-
, NVL((
59-
SELECT
60-
points
61-
FROM practice_component_state pcs
62-
WHERE pcs.round_id = rc.round_id
63-
AND pcs.component_id = c.component_id
64-
AND pcs.coder_id = @userId@
65-
), 0) AS my_points
16+
, NVL( CASE WHEN pcs.status_id < 120 THEN 'New'::nvarchar(50)
17+
WHEN pcs.status_id = 150 THEN 'Solved'::nvarchar(50)
18+
WHEN pcs.status_id > 120 AND pcs.status_id != 150 THEN 'Viewed'::nvarchar(50)
19+
END, 'New') AS status
20+
, NVL(pcs.points, 0) AS my_points
6621
FROM problem p
22+
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
6723
INNER JOIN component c ON c.problem_id = p.problem_id
6824
INNER JOIN round_component rc ON rc.component_id = c.component_id
6925
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A' AND r.round_type_id = 3
7026
INNER JOIN room ro ON ro.round_id = rc.round_id AND ro.room_type_id = 3 -- practice room
71-
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
72-
WHERE p.status_id = 90
27+
LEFT JOIN practice_component_state pcs ON pcs.round_id = rc.round_id AND pcs.component_id = c.component_id AND pcs.coder_id = @userId@
7328
)) srp
7429
WHERE 1=1

test/sqls/srmPracticeProblems/informixoltp__insert_test_data

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla
44
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3002, 2001, 1, 'method_2', 'TestProblem', 2, 1);
55

66
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4001, "SRM 4001", "A", -1);
7-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5001, 4001, "Practice 4001", "A", 2, 0);
7+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5001, 4001, "Practice 4001", "A", 3, 0);
88
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5001, 5001, 'room ', 3);
99
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5001, 3001, 2, 1, 500);
1010
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7001, 5001, 132456, 3001, 0, 120, 1);
1111
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7002, 5001, 132457, 3001, 0, 110, 1, 001);
1212
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5001, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');
1313

1414
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4002, "SRM 4002", "A", -1);
15-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5002, 4002, "Practice 4002", "A", 2, 0);
15+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5002, 4002, "Practice 4002", "A", 3, 0);
1616
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5002, 5002, 'room ', 3);
1717
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5002, 3001, 2, 1, 250);
1818
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7003, 5002, 132456, 3001, 200, 150, 1);
1919
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7004, 5002, 132457, 3001, 0, 110, 1);
2020
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5002, 1, '2014-09-15 00:00:00', '2014-09-18 00:00:00', 'P');
2121

2222
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4003, "SRM 4003", "A", -1);
23-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5003, 4003, "Practice 4003", "A", 2, 0);
23+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5003, 4003, "Practice 4003", "A", 3, 0);
2424
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5003, 5003, 'room ', 3);
2525
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5003, 3002, 2, 1, 400);
2626
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7005, 5003, 132456, 3002, 100, 150, 1);
2727
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7006, 5003, 132457, 3002, 0, 160, 1);
2828
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5003, 1, '2014-09-25 00:00:00', '2014-09-26 00:00:00', 'P');
2929

3030
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4004, "SRM 4004", "A", -1);
31-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5004, 4004, "Practice 4004", "A", 2, 0);
31+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5004, 4004, "Practice 4004", "A", 3, 0);
3232
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5004, 5004, 'room ', 3);
3333
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5004, 3002, 2, 1, 300);
3434
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7007, 5004, 132456, 3002, 50, 150, 1);
@@ -41,7 +41,7 @@ INSERT INTO problem(problem_id, name, status_id, problem_type_id, proposed_diffi
4141
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3003, 2002, 18, 'method_2', 'problem_class2', 1, 1);
4242

4343
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4005, "SRM 4005", "A", -1);
44-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5005, 4005, "Practice 4005", "A", 2, 0);
44+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5005, 4005, "Practice 4005", "A", 3, 0);
4545
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5005, 5005, 'room ', 3);
4646
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5005, 3003, 2, 1, 200);
4747
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7009, 5005, 132456, 3003, 0, 120, 1);
@@ -55,15 +55,15 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla
5555
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3005, 2003, 1, 'method_4', 'TestProblem', 2, 1);
5656

5757
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4006, "SRM 4006", "A", -1);
58-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5006, 4006, "Practice 4006", "A", 2, 0);
58+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5006, 4006, "Practice 4006", "A", 3, 0);
5959
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5006, 5006, 'room ', 3);
6060
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5006, 3004, 2, 1, 100);
6161
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7011, 5006, 132456, 3004, 80, 150, 1);
6262
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7012, 5006, 132457, 3004, 0, 130, 1, 001);
6363
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5006, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');
6464

6565
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4007, "SRM 4007", "A", -1);
66-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5007, 4007, "Practice 4007", "A", 2, 0);
66+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5007, 4007, "Practice 4007", "A", 3, 0);
6767
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5007, 5007, 'room ', 3);
6868
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5007, 3005, 2, 1, 450);
6969
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7013, 5007, 132456, 3005, 100, 150, 1);
@@ -79,14 +79,14 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla
7979

8080
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4008, "SRM 4008", "A", -1);
8181

82-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5008, 4008, "Practice 4008", "A", 2, 0);
82+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5008, 4008, "Practice 4008", "A", 3, 0);
8383
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5008, 5008, 'room ', 3);
8484
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5008, 3006, 2, 1, 100);
8585
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7015, 5008, 132456, 3006, 80, 150, 1);
8686
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7016, 5008, 132457, 3006, 0, 130, 1, 001);
8787
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5008, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');
8888

89-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5009, 4008, "Practice 4008", "A", 2, 0);
89+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5009, 4008, "Practice 4008", "A", 3, 0);
9090
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5009, 5009, 'room ', 3);
9191
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5009, 3006, 2, 1, 100);
9292
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7017, 5009, 132456, 3006, 80, 150, 1);
@@ -95,7 +95,7 @@ INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VA
9595

9696

9797
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4009, "SRM 4009", "A", -1);
98-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5010, 4009, "Practice 4009", "A", 2, 0);
98+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5010, 4009, "Practice 4009", "A", 3, 0);
9999
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5010, 5010, 'room ', 3);
100100
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5010, 3007, 2, 1, 450);
101101
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7019, 5010, 132456, 3007, 100, 150, 1);
@@ -108,7 +108,7 @@ INSERT INTO problem(problem_id, name, status_id, problem_type_id, proposed_diffi
108108
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3008, 2005, 18, 'method_2', 'problem_class2', 1, 1);
109109

110110
INSERT INTO contest (contest_id, name, status, group_id) VALUES (4010, "SRM 4010", "A", -1);
111-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5011, 4010, "Practice 4010", "A", 2, 0);
111+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5011, 4010, "Practice 4010", "A", 3, 0);
112112
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5011, 5011, 'room ', 3);
113113
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5011, 3008, 2, 1, 200);
114114
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7020, 5011, 132456, 3008, 0, 110, 1);

test/test_files/srmPracticeProblems/expected_srm_practice_problems_1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"problemType": "Long",
2121
"problemId": 2001,
2222
"componentId": 3001,
23-
"status": "Solved",
23+
"status": "Viewed",
2424
"roundId": 5001,
2525
"roomId": 5001,
2626
"problemName": "Problem 2001",

test/test_files/srmPracticeProblems/expected_srm_practice_problems_11.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"problemType": "Long",
99
"problemId": 2001,
1010
"componentId": 3001,
11-
"status": "Solved",
11+
"status": "Viewed",
1212
"roundId": 5001,
1313
"roomId": 5001,
1414
"problemName": "Problem 2001",

test/test_files/srmPracticeProblems/expected_srm_practice_problems_2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"problemType": "Long",
3333
"problemId": 2001,
3434
"componentId": 3002,
35-
"status": "Solved",
35+
"status": "Viewed",
3636
"roundId": 5003,
3737
"roomId": 5003,
3838
"problemName": "Problem 2001",

test/test_files/srmPracticeProblems/expected_srm_practice_problems_3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"problemType": "Long",
99
"problemId": 2001,
1010
"componentId": 3001,
11-
"status": "Solved",
11+
"status": "Viewed",
1212
"roundId": 5001,
1313
"roomId": 5001,
1414
"problemName": "Problem 2001",

test/test_files/srmPracticeProblems/expected_srm_practice_problems_8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"problemType": "Long",
2121
"problemId": 2001,
2222
"componentId": 3001,
23-
"status": "Solved",
23+
"status": "Viewed",
2424
"roundId": 5001,
2525
"roomId": 5001,
2626
"problemName": "Problem 2001",

test/test_files/srmPracticeProblems/expected_srm_practice_problems_9.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
{
22
"pageIndex": 1,
33
"pageSize": 10,
4-
"total": 1,
4+
"total": 0,
55
"data": [
6+
{
7+
"myPoints": 0,
8+
"problemType": "Long",
9+
"problemId": 2001,
10+
"componentId": 3001,
11+
"status": "Viewed",
12+
"roundId": 5001,
13+
"roomId": 5001,
14+
"problemName": "Problem 2001",
15+
"points": 500,
16+
"divisionId": 1
17+
},
618
{
719
"myPoints": 0,
820
"problemType": "Single",

0 commit comments

Comments
 (0)