From 058093185e9365b1edbd5472ec4953af63cc80da Mon Sep 17 00:00:00 2001 From: Sven Steudte Date: Sat, 18 Aug 2018 05:32:24 +0200 Subject: [PATCH] Added more performance to image insertion --- decoder/image.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/decoder/image.py b/decoder/image.py index 979db899..231c49e3 100644 --- a/decoder/image.py +++ b/decoder/image.py @@ -34,6 +34,7 @@ def encode_callsign(callsign): imageProcessor = None imageData = {} +imageDataLcl = {} lock = threading.RLock() def imgproc(): @@ -61,7 +62,7 @@ def imgproc(): w = time.time() def insert_image(db, receiver, call, data_b91): - global imageProcessor,imageData,w + global imageProcessor,imageData,imageDataLcl,w data = base91.decode(data_b91) if len(data) != 174: @@ -117,17 +118,20 @@ def insert_image(db, receiver, call, data_b91): (call, timd, imageID, packetID, data, _id) ) - if w+0.5 < time.time(): + if w+1 < time.time(): db.commit() + with lock: + imageData = imageDataLcl + imageDataLcl = {} w = time.time() allData = '' + cur.execute("SELECT `data` FROM `image` WHERE `id` = %s ORDER BY `packetID`", (_id,)) for data, in cur.fetchall(): allData += '55' + data + (144*'0') - with lock: - imageData[_id] = (call, binascii.unhexlify(allData)) + imageDataLcl[_id] = (call, binascii.unhexlify(allData)) if imageProcessor is None: imageProcessor = threading.Thread(target=imgproc)