From 90b305e26d7ed302b8a62972d59a65c4199104ca Mon Sep 17 00:00:00 2001 From: j Date: Wed, 28 May 2014 17:42:19 +0200 Subject: [PATCH] dont trigger activity event more than every 5 seconds --- oml/item/scan.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/oml/item/scan.py b/oml/item/scan.py index 8b96175..adc45ae 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -5,6 +5,7 @@ from __future__ import division import os import shutil from datetime import datetime +import time import ox @@ -154,6 +155,7 @@ def run_import(options=None): trigger_event('activity', state.activity) position = 0 added = 0 + last = 0 for f in ox.sorted_strings(books): position += 1 if not os.path.exists(f): @@ -170,10 +172,11 @@ def run_import(options=None): shutil.copy(f_import, f) file = add_file(id, f, prefix_books, f_import) file.move() - item = file.item - if listname: - listitems.append(item.id) added += 1 + if listname: + listitems.append(file.item.id) + if time.time() - last > 5: + last = time.time() state.activity = { 'activity': 'import', 'progress': [position, len(books)], @@ -181,8 +184,6 @@ def run_import(options=None): 'added': added, } trigger_event('activity', state.activity) - elif listname: - listitems.append(file.item.id) if state.activity.get('cancel'): state.activity = {}