utopia-php/database

Update `Utopia\Database\Database->count()` to ignore non-filter queries

Closed this issue · 0 comments

In several places in Appwrite, we have to do:

        $filterQueries = Query::groupByType($queries)['filters'];

        $response->dynamic(new Document([
            'users' => $dbForProject->find('users', $queries),
            'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT),
        ]), Response::MODEL_USER_LIST);

It would be much cleaner to have Utopia\Database\Database->count() grab only the filters so that the code can be simplified to:

-        $filterQueries = Query::groupByType($queries)['filters'];

        $response->dynamic(new Document([
            'users' => $dbForProject->find('users', $queries),
-            'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT),
+            'total' => $dbForProject->count('users', $queries, APP_LIMIT_COUNT),
        ]), Response::MODEL_USER_LIST);