1414
1515use MongoDB \BSON \UTCDateTime ;
1616use MongoDB \Collection ;
17+ use MongoDB \Driver \CursorInterface ;
1718use MongoDB \Model \BSONDocument ;
1819use Omines \DataTablesBundle \Adapter \AbstractAdapter ;
1920use Omines \DataTablesBundle \Adapter \AdapterQuery ;
@@ -56,7 +57,17 @@ protected function prepareQuery(AdapterQuery $query): void
5657 }
5758 }
5859
60+ $ state = $ query ->getState ();
61+
62+ $ filter = $ this ->buildFilter ($ state );
63+ $ options = $ this ->buildOptions ($ state );
64+
5965 $ query ->setTotalRows ($ this ->collection ->count ());
66+ $ query ->setFilteredRows ($ this ->collection ->count ($ filter ));
67+ $ cursor = $ this ->collection ->find ($ filter , $ options );
68+ $ cursor ->setTypeMap (['root ' => 'array ' , 'document ' => 'array ' ]);
69+
70+ $ query ->set ('cursor ' , $ cursor );
6071 }
6172
6273 protected function mapPropertyPath (AdapterQuery $ query , AbstractColumn $ column ): ?string
@@ -69,14 +80,8 @@ protected function mapPropertyPath(AdapterQuery $query, AbstractColumn $column):
6980 */
7081 protected function getResults (AdapterQuery $ query ): \Traversable
7182 {
72- $ state = $ query ->getState ();
73-
74- $ filter = $ this ->buildFilter ($ state );
75- $ options = $ this ->buildOptions ($ state );
76-
77- $ query ->setFilteredRows ($ this ->collection ->count ($ filter ));
78- $ cursor = $ this ->collection ->find ($ filter , $ options );
79- $ cursor ->setTypeMap (['root ' => 'array ' , 'document ' => 'array ' ]);
83+ /** @var CursorInterface $cursor */
84+ $ cursor = $ query ->get ('cursor ' );
8085
8186 /** @var BSONDocument $result */
8287 foreach ($ cursor as $ result ) {
0 commit comments