Merge branch 'master' of github.com:Kozea/radicale

This commit is contained in:
Guillaume Ayoub 2016-07-12 12:30:37 +02:00
commit 52d67a906b
28 changed files with 28 additions and 17 deletions

View File

@ -1,3 +1,3 @@
[pytest] [pytest]
addopts = --flake8 --isort --cov radicale/ tests addopts = --flake8 --isort --cov radicale/ radicale/tests
norecursedirs = dist .cache .git build *.egg-info .eggs venv norecursedirs = dist .cache .git build *.egg-info .eggs venv

View File

@ -35,7 +35,8 @@ import time
from contextlib import contextmanager from contextlib import contextmanager
from hashlib import md5 from hashlib import md5
from importlib import import_module from importlib import import_module
from uuid import uuid4 from itertools import groupby
from random import getrandbits
import vobject import vobject
@ -231,6 +232,15 @@ class BaseCollection:
for href in set(hrefs): for href in set(hrefs):
yield self.get(href) yield self.get(href)
def pre_filtered_list(self, filters):
"""List collection items with optional pre filtering.
This could largely improve performance of reports depending on
the filters and this implementation.
This returns all event by default
"""
return [self.get(href) for href, _ in self.list()]
def has(self, href): def has(self, href):
"""Check if an item exists by its href. """Check if an item exists by its href.
@ -372,25 +382,26 @@ class Collection(BaseCollection):
items = [] items = []
for content in ("vevent", "vtodo", "vjournal"): for content in ("vevent", "vtodo", "vjournal"):
items.extend(getattr(collection, "%s_list" % content, [])) items.extend(getattr(collection, "%s_list" % content, []))
processed_uids = []
for i, item in enumerate(items): def get_uid(item):
uid = getattr(item, "uid", None) return hasattr(item, 'uid') and item.uid.value
if uid in processed_uids:
continue items_by_uid = groupby(
sorted(items, key=get_uid), get_uid)
for uid, items in items_by_uid:
new_collection = vobject.iCalendar() new_collection = vobject.iCalendar()
for item in items:
new_collection.add(item) new_collection.add(item)
if uid: file_name = hex(getrandbits(32))[2:]
processed_uids.append(uid) self.upload(file_name, new_collection)
# search for items with same UID
for oitem in items[i+1:]:
if getattr(oitem, "uid", None) == uid:
new_collection.add(oitem)
self.upload(uuid4().hex, new_collection)
elif tag == "VCARD": elif tag == "VCARD":
self.set_meta("tag", "VADDRESSBOOK") self.set_meta("tag", "VADDRESSBOOK")
if collection: if collection:
for card in collection: for card in collection:
self.upload(uuid4().hex, card) file_name = hex(getrandbits(32))[2:]
self.upload(file_name, card)
return self return self
def list(self): def list(self):

View File

@ -837,7 +837,7 @@ def report(path, xml_request, collection):
else: else:
# Reference is a collection # Reference is a collection
path = hreference path = hreference
items = [collection.get(href) for href, etag in collection.list()] items = collection.pre_filtered_list(filters)
for item in items: for item in items:
if filters: if filters: