Skip to content

Commit 7646767

Browse files
committed
Remove old query
1 parent af5c9e1 commit 7646767

File tree

1 file changed

+7
-99
lines changed

1 file changed

+7
-99
lines changed

lib/cadet/assessments/assessments.ex

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,118 +1242,26 @@ defmodule Cadet.Assessments do
12421242
def all_submissions_by_grader_for_index(
12431243
grader = %CourseRegistration{course_id: course_id},
12441244
group_only \\ false,
1245-
ungraded_only \\ false
1245+
_ungraded_only \\ false
12461246
) do
12471247
show_all = not group_only
12481248

1249-
group_where =
1250-
if show_all,
1251-
do: "",
1252-
else:
1253-
"where s.student_id in (select cr.id from course_registrations cr inner join groups g on cr.group_id = g.id where g.leader_id = $1) or s.student_id = $1"
1254-
12551249
group_filter =
12561250
if show_all,
12571251
do: "",
12581252
else:
12591253
"AND s.student_id IN (SELECT cr.id FROM course_registrations AS cr INNER JOIN groups AS g ON cr.group_id = g.id WHERE g.leader_id = #{grader.id}) OR s.student_id = #{grader.id}"
12601254

1261-
ungraded_where =
1262-
if ungraded_only,
1263-
do: "where s.\"gradedCount\" < assts.\"questionCount\"",
1264-
else: ""
1265-
1266-
params = if show_all, do: [], else: [grader.id]
1255+
# TODO: Restore ungraded filtering
1256+
# ... or more likely, decouple email logic from this function
1257+
# ungraded_where =
1258+
# if ungraded_only,
1259+
# do: "where s.\"gradedCount\" < assts.\"questionCount\"",
1260+
# else: ""
12671261

12681262
# We bypass Ecto here and use a raw query to generate JSON directly from
12691263
# PostgreSQL, because doing it in Elixir/Erlang is too inefficient.
12701264

1271-
# TODO: Remove old query
1272-
case Repo.query(
1273-
"""
1274-
select json_agg(q)::TEXT from
1275-
(
1276-
select
1277-
s.id,
1278-
s.status,
1279-
s."unsubmittedAt",
1280-
s.xp,
1281-
s."xpAdjustment",
1282-
s."xpBonus",
1283-
s."gradedCount",
1284-
assts.jsn as assessment,
1285-
students.jsn as student,
1286-
unsubmitters.jsn as "unsubmittedBy"
1287-
from
1288-
(select
1289-
s.id,
1290-
s.student_id,
1291-
s.assessment_id,
1292-
s.status,
1293-
s.unsubmitted_at as "unsubmittedAt",
1294-
s.unsubmitted_by_id,
1295-
sum(ans.xp) as xp,
1296-
sum(ans.xp_adjustment) as "xpAdjustment",
1297-
s.xp_bonus as "xpBonus",
1298-
count(ans.id) filter (where ans.grader_id is not null) as "gradedCount"
1299-
from submissions s
1300-
left join
1301-
answers ans on s.id = ans.submission_id
1302-
#{group_where}
1303-
group by s.id) s
1304-
inner join
1305-
(select
1306-
a.id, a."questionCount", to_json(a) as jsn
1307-
from
1308-
(select
1309-
a.id,
1310-
a.title,
1311-
a.number as "assessmentNumber",
1312-
bool_or(ac.is_manually_graded) as "isManuallyGraded",
1313-
max(ac.type) as "type",
1314-
sum(q.max_xp) as "maxXp",
1315-
count(q.id) as "questionCount"
1316-
from assessments a
1317-
left join
1318-
questions q on a.id = q.assessment_id
1319-
inner join
1320-
assessment_configs ac on ac.id = a.config_id
1321-
where a.course_id = #{course_id}
1322-
group by a.id) a) assts on assts.id = s.assessment_id
1323-
inner join
1324-
(select
1325-
cr.id, to_json(cr) as jsn
1326-
from
1327-
(select
1328-
cr.id,
1329-
u.name as "name",
1330-
u.username as "username",
1331-
g.name as "groupName",
1332-
g.leader_id as "groupLeaderId"
1333-
from course_registrations cr
1334-
left join
1335-
groups g on g.id = cr.group_id
1336-
inner join
1337-
users u on u.id = cr.user_id) cr) students on students.id = s.student_id
1338-
left join
1339-
(select
1340-
cr.id, to_json(cr) as jsn
1341-
from
1342-
(select
1343-
cr.id,
1344-
u.name
1345-
from course_registrations cr
1346-
inner join
1347-
users u on u.id = cr.user_id) cr) unsubmitters on s.unsubmitted_by_id = unsubmitters.id
1348-
#{ungraded_where}
1349-
) q
1350-
""",
1351-
params
1352-
) do
1353-
{:ok, %{rows: [[nil]]}} -> {:ok, "[]"}
1354-
{:ok, %{rows: [[json]]}} -> {:ok, json}
1355-
end
1356-
13571265
# TODO: Implement filtering
13581266
submissions =
13591267
case Repo.query("""

0 commit comments

Comments
 (0)