@@ -38,12 +38,30 @@ public function getProfileInfo(Language $language): array
3838
3939 return $ query
4040 ->addSelect ('ch.name ' )
41- ->addSelect ('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id) as items ' )
42- ->addSelect ('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id
43- AND processed_at IS NOT NULL) as processed ' )
44- ->addSelect ('(SELECT count(*) FROM exporter.export_error el WHERE el.export_id = e.id) as errors ' )
41+ ->addSelect ('CASE WHEN ee.errors IS NULL THEN 0 ELSE ee.errors END AS errors ' )
42+ ->addSelect ('CASE WHEN ep.processed IS NULL THEN 0 ELSE ep.processed END AS processed ' )
43+ ->addSelect ('CASE WHEN ei.items IS NULL THEN 0 ELSE ei.items END AS items ' )
4544 ->orderBy ('started_at ' , 'DESC ' )
4645 ->join ('e ' , self ::TABLE_CHANNEL , 'ch ' , 'ch.id = e.channel_id ' )
46+ ->leftJoin (
47+ 'e ' ,
48+ '(SELECT count(*) as errors, export_id FROM exporter.export_error GROUP BY export_id) ' ,
49+ 'ee ' ,
50+ 'ee.export_id = e.id '
51+ )
52+ ->leftJoin (
53+ 'e ' ,
54+ '(SELECT count(*) as items, export_id FROM exporter.export_line GROUP BY export_id) ' ,
55+ 'ei ' ,
56+ 'ei.export_id = e.id '
57+ )
58+ ->leftJoin (
59+ 'e ' ,
60+ '(SELECT count(*) as processed, export_id FROM exporter.export_line
61+ WHERE processed_at IS NOT NULL GROUP BY export_id) ' ,
62+ 'ep ' ,
63+ 'ep.export_id = e.id '
64+ )
4765 ->setMaxResults (10 )
4866 ->execute ()
4967 ->fetchAll ();
@@ -57,11 +75,29 @@ public function getInformation(ExportId $exportId): array
5775 $ query = $ this ->getQuery ();
5876
5977 return $ query
60- ->addSelect ('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id) as items ' )
61- ->addSelect ('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id
62- AND processed_at IS NOT NULL) as processed ' )
63- ->addSelect ('(SELECT count(*) FROM exporter.export_error el WHERE el.export_id = e.id) as errors ' )
78+ ->addSelect ('CASE WHEN ee.errors IS NULL THEN 0 ELSE ee.errors END AS errors ' )
79+ ->addSelect ('CASE WHEN ep.processed IS NULL THEN 0 ELSE ep.processed END AS processed ' )
80+ ->addSelect ('CASE WHEN ei.items IS NULL THEN 0 ELSE ei.items END AS items ' )
6481 ->where ($ query ->expr ()->eq ('id ' , ':exportId ' ))
82+ ->leftJoin (
83+ 'e ' ,
84+ '(SELECT count(*) as errors, export_id FROM exporter.export_error GROUP BY export_id) ' ,
85+ 'ee ' ,
86+ 'ee.export_id = e.id '
87+ )
88+ ->leftJoin (
89+ 'e ' ,
90+ '(SELECT count(*) as items, export_id FROM exporter.export_line GROUP BY export_id) ' ,
91+ 'ei ' ,
92+ 'ei.export_id = e.id '
93+ )
94+ ->leftJoin (
95+ 'e ' ,
96+ '(SELECT count(*) as processed, export_id FROM exporter.export_line
97+ WHERE processed_at IS NOT NULL GROUP BY export_id) ' ,
98+ 'ep ' ,
99+ 'ep.export_id = e.id '
100+ )
65101 ->setParameter (':exportId ' , $ exportId ->getValue ())
66102 ->execute ()
67103 ->fetch ();
0 commit comments