@@ -14,28 +14,32 @@ class DataImportTable implements Table
1414
1515 public function query (): Builder
1616 {
17- $ query = DataImport::selectRaw ('
17+ return DataImport::selectRaw ("
1818 data_imports.id, data_imports.type, data_imports.status, data_imports.status as computedStatus,
1919 files.original_name as name, data_imports.successful, data_imports.failed, data_imports.created_at,
20- TIME(data_imports.created_at) as time, people.name as createdBy, rejected_imports.id as rejectedId
21- ' )->join ('files ' , function ($ join ) {
20+ TIME(data_imports.created_at) as time, people.name as createdBy, rejected_imports.id as rejectedId,
21+ {$ this ->rawDuration ()} as duration
22+ " )->join ('files ' , function ($ join ) {
2223 $ join ->on ('files.attachable_id ' , 'data_imports.id ' )
2324 ->where ('files.attachable_type ' , DataImport::class);
2425 })->join ('users ' , 'files.created_by ' , '= ' , 'users.id ' )
2526 ->join ('people ' , 'users.person_id ' , '= ' , 'people.id ' )
2627 ->leftJoin ('rejected_imports ' , 'data_imports.id ' , '= ' , 'rejected_imports.data_import_id ' )
2728 ->leftJoin ('files as rejected_files ' , function ($ join ) {
2829 $ join ->on ('rejected_files.attachable_id ' , 'rejected_imports.id ' )
29- ->where ('rejected_files.attachable_type ' , RejectedImportSummary::class);
30+ ->where ('rejected_files.attachable_type ' , RejectedImportSummary::class);
3031 });
31-
32- return $ query ->selectRaw (DB ::getDriverName () === 'sqlite '
33- ? '0 as duration '
34- : 'sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at)) as duration ' );
3532 }
3633
3734 public function templatePath (): string
3835 {
3936 return static ::TemplatePath;
4037 }
38+
39+ private function rawDuration ()
40+ {
41+ return DB ::getDriverName () === 'sqlite '
42+ ? '0 '
43+ : 'sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at)) ' ;
44+ }
4145}
0 commit comments