dont trigger activity event more than every 5 seconds
This commit is contained in:
parent
9cd4f35229
commit
90b305e26d
1 changed files with 6 additions and 5 deletions
|
@ -5,6 +5,7 @@ from __future__ import division
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
|
@ -154,6 +155,7 @@ def run_import(options=None):
|
||||||
trigger_event('activity', state.activity)
|
trigger_event('activity', state.activity)
|
||||||
position = 0
|
position = 0
|
||||||
added = 0
|
added = 0
|
||||||
|
last = 0
|
||||||
for f in ox.sorted_strings(books):
|
for f in ox.sorted_strings(books):
|
||||||
position += 1
|
position += 1
|
||||||
if not os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
|
@ -170,10 +172,11 @@ def run_import(options=None):
|
||||||
shutil.copy(f_import, f)
|
shutil.copy(f_import, f)
|
||||||
file = add_file(id, f, prefix_books, f_import)
|
file = add_file(id, f, prefix_books, f_import)
|
||||||
file.move()
|
file.move()
|
||||||
item = file.item
|
|
||||||
if listname:
|
|
||||||
listitems.append(item.id)
|
|
||||||
added += 1
|
added += 1
|
||||||
|
if listname:
|
||||||
|
listitems.append(file.item.id)
|
||||||
|
if time.time() - last > 5:
|
||||||
|
last = time.time()
|
||||||
state.activity = {
|
state.activity = {
|
||||||
'activity': 'import',
|
'activity': 'import',
|
||||||
'progress': [position, len(books)],
|
'progress': [position, len(books)],
|
||||||
|
@ -181,8 +184,6 @@ def run_import(options=None):
|
||||||
'added': added,
|
'added': added,
|
||||||
}
|
}
|
||||||
trigger_event('activity', state.activity)
|
trigger_event('activity', state.activity)
|
||||||
elif listname:
|
|
||||||
listitems.append(file.item.id)
|
|
||||||
|
|
||||||
if state.activity.get('cancel'):
|
if state.activity.get('cancel'):
|
||||||
state.activity = {}
|
state.activity = {}
|
||||||
|
|
Loading…
Reference in a new issue