Skip to content

Commit

Permalink
Merge pull request #126 from icgood/mbx
Browse files Browse the repository at this point in the history
Fix mailbox CRUD operations on redis
  • Loading branch information
icgood committed Dec 5, 2021
2 parents 4cdabda + 01e953e commit 92f01e2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
26 changes: 10 additions & 16 deletions pymap/backend/redis/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,13 @@ def delimiter(self) -> str:
return '/'

async def set_subscribed(self, name: str, subscribed: bool) -> None:
async with self._redis.pipeline() as multi:
multi.unwatch()
if subscribed:
multi.sadd(self._keys.subscribed, name)
else:
multi.srem(self._keys.subscribed, name)
await multi.execute()
if subscribed:
await self._redis.sadd(self._keys.subscribed, name)
else:
await self._redis.srem(self._keys.subscribed, name)

async def list_subscribed(self) -> ListTree:
async with self._redis.pipeline() as multi:
multi.unwatch()
multi.smembers(self._keys.subscribed)
_, mailboxes = await multi.execute()
mailboxes = await self._redis.smembers(self._keys.subscribed)
return ListTree(self.delimiter).update('INBOX', *(
modutf7_decode(name) for name in mailboxes))

Expand Down Expand Up @@ -342,11 +336,11 @@ async def delete_mailbox(self, name: str) -> None:

async def rename_mailbox(self, before: str, after: str) -> None:
redis = self._redis
async with redis.pipeline() as multi:
multi.unwatch()
multi.watch(self._keys.mailboxes)
multi.hgetall(self._keys.mailboxes)
_, _, all_keys = await multi.execute()
async with redis.pipeline() as pipe:
await pipe.watch(self._keys.mailboxes)
pipe.multi()
pipe.hgetall(self._keys.mailboxes)
all_keys, = await pipe.execute()
all_mbx = {modutf7_decode(key): ns for key, ns in all_keys.items()}
tree = ListTree(self.delimiter).update('INBOX', *all_mbx.keys())
before_entry = tree.get(before)
Expand Down
10 changes: 1 addition & 9 deletions pymap/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from __future__ import annotations

import logging
from collections.abc import Callable, Iterator
from itertools import chain
from collections.abc import Callable
from types import MethodType
from typing import Any, Optional
from weakref import finalize, ref, WeakMethod, WeakSet
Expand Down Expand Up @@ -79,13 +78,6 @@ def _check(self, seen: set[HealthStatus]) -> None:
if watcher not in seen:
watcher._check(seen)

def walk(self) -> Iterator[HealthStatus]:
"""Traverses the tree of :class:`HealthStatus` objects rooted at this
object, breadth-first.
"""
return chain([self], *(dep.walk() for dep in self._dependencies))

def new_dependency(self, initial: bool = True, *,
name: str = '') -> HealthStatus:
"""Adds a new health status as a dependency of this status. All
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='pymap',
version='0.26.0',
version='0.26.1',
author='Ian Good',
author_email='ian@icgood.net',
description='Lightweight, asynchronous IMAP serving in Python.',
Expand Down
8 changes: 0 additions & 8 deletions test/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ def test_name(self) -> None:
child3 = child1.new_dependency(name='oof')
self.assertEqual('foo.bar.oof', child3.name)

def test_walk(self) -> None:
status = HealthStatus(name='foo')
child1 = status.new_dependency(name='bar')
child2 = status.new_dependency(name='baz')
child3 = child1.new_dependency(name='oof')
tree = list(status.walk())
self.assertEqual([status, child1, child3, child2], tree)

def test_set(self) -> None:
status = HealthStatus()
self.assertTrue(status.healthy)
Expand Down

0 comments on commit 92f01e2

Please sign in to comment.