@@ -122,47 +122,29 @@ public function index(Request $request, $getTotal = false, User $user = null)
122122
123123 $ this ->applyForCurrentUser ($ query , $ user );
124124
125- try {
126- // Count up the total number of results, but
127- // watch for PMQL query exceptions and handle
128- // them if they occur
129- $ totalResultCount = $ query ->count ();
130- } catch (QueryException $ e ) {
131- return $ this ->handleQueryException ($ e );
132- }
133-
134- // If only the total is being requested (by a Saved Search), send it now
135- if ($ getTotal === true ) {
136- return $ totalResultCount ;
137- }
138-
139125 // Apply filter overdue
140126 $ query ->overdue ($ request ->input ('overdue ' ));
141127
142- // If we should manually add pagination to the
143- // query in advance (also used by saved search)
144- if ($ this ->isPaginationEnabled ()) {
145- $ query ->limit ($ request ->input ('per_page ' , 10 ));
128+ // If only the total is being requested (by a Saved Search), send it now
129+ if ($ getTotal === true ) {
130+ return $ query ->count ();
146131 }
147132
148133 try {
149- $ response = $ query ->get ( );
134+ $ response = $ query ->paginate ( $ request -> input ( ' per_page ' , 10 ) );
150135 } catch (QueryException $ e ) {
151136 return $ this ->handleQueryException ($ e );
152137 }
153138
154139 $ response = $ this ->applyUserFilter ($ response , $ request , $ user );
155140
156- // Map each item through its resource
157- $ response = $ this ->applyResource ($ response );
158-
159141 $ inOverdueQuery = ProcessRequestToken::query ()
160142 ->whereIn ('id ' , $ response ->pluck ('id ' ))
161143 ->where ('due_at ' , '< ' , Carbon::now ());
162144
163145 $ response ->inOverdue = $ inOverdueQuery ->count ();
164146
165- return new TaskCollection ($ response, $ totalResultCount );
147+ return new TaskCollection ($ response );
166148 }
167149
168150 /**
0 commit comments