mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-26 14:47:44 +00:00
Some minor optimizations
In the case of singlefile this doesn't help much as the whole implementation is algorithmically flawed. It's not like i care enough to make the code even more complicated though.
This commit is contained in:
parent
6a63dcec81
commit
e4ae04aaa1
2 changed files with 5 additions and 12 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
from .base import Item, Storage
|
from .base import Item, Storage
|
||||||
from ..exceptions import NotFoundError
|
from ..exceptions import NotFoundError
|
||||||
from ..utils import expand_path, get_password, request
|
from ..utils import expand_path, get_password, request
|
||||||
from ..utils.compat import text_type, urlparse
|
from ..utils.compat import iteritems, text_type, urlparse
|
||||||
from ..utils.vobject import split_collection
|
from ..utils.vobject import split_collection
|
||||||
|
|
||||||
USERAGENT = 'vdirsyncer'
|
USERAGENT = 'vdirsyncer'
|
||||||
|
|
@ -107,17 +107,14 @@ class HttpStorage(Storage):
|
||||||
def list(self):
|
def list(self):
|
||||||
r = request('GET', self.url, **self._settings)
|
r = request('GET', self.url, **self._settings)
|
||||||
self._items = {}
|
self._items = {}
|
||||||
rv = []
|
|
||||||
for item in split_collection(r.text):
|
for item in split_collection(r.text):
|
||||||
item = Item(item)
|
item = Item(item)
|
||||||
href = self._get_href(item)
|
href = self._get_href(item)
|
||||||
etag = item.hash
|
etag = item.hash
|
||||||
self._items[href] = item, etag
|
self._items[href] = item, etag
|
||||||
rv.append((href, etag))
|
|
||||||
|
|
||||||
# we can't use yield here because we need to populate our
|
return ((href, etag) for href, (item, etag) in iteritems(self._items))
|
||||||
# dict even if the user doesn't exhaust the iterator
|
|
||||||
return rv
|
|
||||||
|
|
||||||
def get(self, href):
|
def get(self, href):
|
||||||
if self._items is None:
|
if self._items is None:
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import collections
|
||||||
from .. import exceptions, log
|
from .. import exceptions, log
|
||||||
from .base import Item, Storage
|
from .base import Item, Storage
|
||||||
from ..utils import checkfile, expand_path, safe_write
|
from ..utils import checkfile, expand_path, safe_write
|
||||||
from ..utils.compat import itervalues
|
from ..utils.compat import iteritems, itervalues
|
||||||
from ..utils.vobject import join_collection, split_collection
|
from ..utils.vobject import join_collection, split_collection
|
||||||
|
|
||||||
logger = log.get(__name__)
|
logger = log.get(__name__)
|
||||||
|
|
@ -94,17 +94,13 @@ class SingleFileStorage(Storage):
|
||||||
if not text:
|
if not text:
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
rv = []
|
|
||||||
for item in split_collection(text):
|
for item in split_collection(text):
|
||||||
item = Item(item)
|
item = Item(item)
|
||||||
href = self._get_href(item)
|
href = self._get_href(item)
|
||||||
etag = item.hash
|
etag = item.hash
|
||||||
self._items[href] = item, etag
|
self._items[href] = item, etag
|
||||||
rv.append((href, etag))
|
|
||||||
|
|
||||||
# we can't use yield here because we need to populate our
|
return ((href, etag) for href, (item, etag) in iteritems(self._items))
|
||||||
# dict even if the user doesn't exhaust the iterator
|
|
||||||
return rv
|
|
||||||
|
|
||||||
def get(self, href):
|
def get(self, href):
|
||||||
if self._items is None:
|
if self._items is None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue