From e75d653f700dcf9a0a31550384d6511c47d024c1 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Wed, 24 Aug 2016 09:51:38 +0200 Subject: Add a method to find list using properties filters This allows the filtering to be done at the database level. It also makes list pagination much more efficient, since the slicing is done at the database level too. --- src/mailman/rest/lists.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/mailman/rest/lists.py') diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index 3d2ed072c..dc1d75203 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -107,16 +107,14 @@ class _ListBase(CollectionMixin): def _get_collection(self, request): """See `CollectionMixin`.""" - return self._filter_lists( - request, list(getUtility(IListManager))) + return self._filter_lists(request) - def _filter_lists(self, request, lists): + def _filter_lists(self, request, **kw): """Filter a collection using query parameters.""" only_advertised = request.get_param_as_bool('only_advertised') if only_advertised: - return [l for l in lists if l.advertised] - else: - return lists + kw['advertised'] = True + return getUtility(IListManager).find(**kw) @public @@ -308,8 +306,7 @@ class ListsForDomain(_ListBase): def _get_collection(self, request): """See `CollectionMixin`.""" - return self._filter_lists( - request, list(self._domain.mailing_lists)) + return self._filter_lists(request, mail_host=self._domain.mail_host) @public -- cgit v1.2.3-70-g09d2