Move filter registration to session store

This commit is contained in:
lash 2022-03-18 00:02:18 +00:00
parent 18f16d878f
commit 78bd6ca538
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 29 additions and 19 deletions

View File

@ -14,13 +14,14 @@ class SyncSession:
self.get = self.session_store.get self.get = self.session_store.get
self.next = self.session_store.next_item self.next = self.session_store.next_item
self.item = None self.item = None
self.filters = self.session_store.filters
def register(self, fltr): # def register(self, fltr):
if self.started: # if self.started:
raise RuntimeError('filters cannot be changed after syncer start') # raise RuntimeError('filters cannot be changed after syncer start')
self.session_store.register(fltr) # self.session_store.register(fltr)
self.filters.append(fltr) # self.filters.append(fltr)
def start(self, offset=0, target=-1): def start(self, offset=0, target=-1):

View File

@ -84,3 +84,7 @@ class SyncState:
def next_item(self): def next_item(self):
return None return None
def filters(self):
return []

View File

@ -151,7 +151,12 @@ class SyncFsStore:
factory = SimpleFileStoreFactory(base_filter_path, binary=True) factory = SimpleFileStoreFactory(base_filter_path, binary=True)
filter_state_backend = PersistedState(factory.add, 0, check_alias=False) filter_state_backend = PersistedState(factory.add, 0, check_alias=False)
self.filter_state = SyncState(filter_state_backend) self.filter_state = SyncState(filter_state_backend)
self.register = self.filter_state.register self.filters = []
def register(self, fltr):
self.filters.append(fltr)
self.filter_state.register(fltr)
def __create_path(self, base_path, default_path, session_id=None): def __create_path(self, base_path, default_path, session_id=None):

View File

@ -41,9 +41,9 @@ class TestFilter(unittest.TestCase):
def test_filter_basic(self): def test_filter_basic(self):
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
self.session.register(fltr_one) self.store.register(fltr_one)
fltr_two = MockFilter('bar') fltr_two = MockFilter('bar')
self.session.register(fltr_two) self.store.register(fltr_two)
tx_hash = os.urandom(32).hex() tx_hash = os.urandom(32).hex()
tx = MockTx(42, tx_hash) tx = MockTx(42, tx_hash)
@ -57,9 +57,9 @@ class TestFilter(unittest.TestCase):
def test_filter_interrupt(self): def test_filter_interrupt(self):
fltr_one = MockFilter('foo', brk=True) fltr_one = MockFilter('foo', brk=True)
self.session.register(fltr_one) self.store.register(fltr_one)
fltr_two = MockFilter('bar') fltr_two = MockFilter('bar')
self.session.register(fltr_two) self.store.register(fltr_two)
tx_hash = os.urandom(32).hex() tx_hash = os.urandom(32).hex()
tx = MockTx(42, tx_hash) tx = MockTx(42, tx_hash)

View File

@ -95,7 +95,7 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) store.register(fltr_one)
session.start() session.start()
o = session.get(0) o = session.get(0)
@ -108,9 +108,9 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) store.register(fltr_one)
fltr_two = MockFilter('two') fltr_two = MockFilter('two')
session.register(fltr_two) store.register(fltr_two)
session.start() session.start()
o = session.get(0) o = session.get(0)
@ -131,9 +131,9 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) store.register(fltr_one)
fltr_two = MockFilter('bar') fltr_two = MockFilter('bar')
session.register(fltr_two) store.register(fltr_two)
session.start() session.start()
o = session.get(0) o = session.get(0)
@ -148,9 +148,9 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) store.register(fltr_one)
fltr_two = MockFilter('bar') fltr_two = MockFilter('bar')
session.register(fltr_two) store.register(fltr_two)
session.start() session.start()
o = session.get(0) o = session.get(0)
@ -175,7 +175,7 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) store.register(fltr_one)
session.start(target=0) session.start(target=0)
o = session.get(0) o = session.get(0)

View File

@ -43,7 +43,7 @@ class TestFilter(unittest.TestCase):
session = SyncSession(self.store) session = SyncSession(self.store)
session.start(target=1) session.start(target=1)
fltr_one = MockFilter('foo') fltr_one = MockFilter('foo')
session.register(fltr_one) self.store.register(fltr_one)
tx_hash = os.urandom(32).hex() tx_hash = os.urandom(32).hex()
tx = MockTx(42, tx_hash) tx = MockTx(42, tx_hash)