Skip to content

Commit

Permalink
Added update method for bulk updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Feb 14, 2019
1 parent c9a3486 commit 2c07667
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions plone/app/redirector/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def add(self, old_path, new_path):

__setitem__ = add

def update(self, info):
for key, value in info.items():
self.add(key, value)

def remove(self, old_path):
old_path = self._canonical(old_path)
new_path = self._paths.get(old_path, None)
Expand Down
39 changes: 36 additions & 3 deletions plone/app/redirector/tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,46 @@ def test_storage_performance(self):
st = RedirectionStorage()
if VERBOSE:
print('\nRunning plone.app.redirector storage performance tests.')
print('Inserting {0} paths...'.format(pretty_number(NUMBER)))

# Can take long. But 10.000 per second should be no problem.
with self.timeit('Inserting', NUMBER / 10000.0):
for i in range(NUMBER):
# Take one tenth of the items at first.
num = max(int(NUMBER / 10), 1)
with self.timeit(
'Inserting {0} individual items'.format(pretty_number(num)),
num / 10000.0,
):
for i in range(num):
st['/old/{0}'.format(i)] = '/new/{0}'.format(i)

# Should be almost instantaneous.
with self.timeit('Clearing storage'):
st.clear()

# Should be fairly quick.
with self.timeit(
'Preparing {0} items for bulk import'.format(
pretty_number(NUMBER)
),
NUMBER / 100000.0,
):
# Prepare input:
info = {}
for i in range(NUMBER):
info['/old/{0}'.format(i)] = '/new/{0}'.format(i)

# Can take long. But 10.000 per second should be no problem.
with self.timeit(
'Inserting {0} prepared items in bulk'.format(
pretty_number(NUMBER)
),
NUMBER / 10000.0,
):
# Prepare input:
info = {}
for i in range(NUMBER):
info['/old/{0}'.format(i)] = '/new/{0}'.format(i)
st.update(info)

# Should be almost instantaneous.
with self.timeit('Getting length'):
self.assertEqual(len(st), NUMBER)
Expand Down

0 comments on commit 2c07667

Please sign in to comment.