Unused imports, problematic variable names
This commit is contained in:
parent
01a9124b7d
commit
f3849eeb48
|
@ -1,5 +1,4 @@
|
||||||
import collections
|
import collections
|
||||||
import pprint
|
|
||||||
from threading import current_thread, enumerate as threadingEnumerate, RLock
|
from threading import current_thread, enumerate as threadingEnumerate, RLock
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ class Inventory(collections.MutableMapping):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
hashes = self._inventory.keys()[:]
|
hashes = self._inventory.keys()[:]
|
||||||
hashes += (hash for hash, in sqlQuery('SELECT hash FROM inventory'))
|
hashes += (x for x, in sqlQuery('SELECT hash FROM inventory'))
|
||||||
return hashes.__iter__()
|
return hashes.__iter__()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
@ -66,23 +65,23 @@ class Inventory(collections.MutableMapping):
|
||||||
def unexpired_hashes_by_stream(self, stream):
|
def unexpired_hashes_by_stream(self, stream):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
t = int(time.time())
|
t = int(time.time())
|
||||||
hashes = [hash for hash, value in self._inventory.items() if value.stream == stream and value.expires > t]
|
hashes = [x for x, value in self._inventory.items() if value.stream == stream and value.expires > t]
|
||||||
hashes += (payload for payload, in sqlQuery('SELECT hash FROM inventory WHERE streamnumber=? AND expirestime>?', stream, t))
|
hashes += (payload for payload, in sqlQuery('SELECT hash FROM inventory WHERE streamnumber=? AND expirestime>?', stream, t))
|
||||||
return hashes
|
return hashes
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
with self.lock: # If you use both the inventoryLock and the sqlLock, always use the inventoryLock OUTSIDE of the sqlLock.
|
with self.lock: # If you use both the inventoryLock and the sqlLock, always use the inventoryLock OUTSIDE of the sqlLock.
|
||||||
with SqlBulkExecute() as sql:
|
with SqlBulkExecute() as sql:
|
||||||
for hash, value in self._inventory.items():
|
for objectHash, value in self._inventory.items():
|
||||||
sql.execute('INSERT INTO inventory VALUES (?, ?, ?, ?, ?, ?)', hash, *value)
|
sql.execute('INSERT INTO inventory VALUES (?, ?, ?, ?, ?, ?)', objectHash, *value)
|
||||||
self._inventory.clear()
|
self._inventory.clear()
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
sqlExecute('DELETE FROM inventory WHERE expirestime<?',int(time.time()) - (60 * 60 * 3))
|
sqlExecute('DELETE FROM inventory WHERE expirestime<?',int(time.time()) - (60 * 60 * 3))
|
||||||
self._streams.clear()
|
self._streams.clear()
|
||||||
for hash, value in self.items():
|
for objectHash, value in self.items():
|
||||||
self._streams[value.stream].add(hash)
|
self._streams[value.stream].add(objectHash)
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -238,9 +237,9 @@ class PendingUpload(object):
|
||||||
self.hashes[objectHash].append(thread.peer)
|
self.hashes[objectHash].append(thread.peer)
|
||||||
# add all objects into the current thread
|
# add all objects into the current thread
|
||||||
else:
|
else:
|
||||||
for hash in self.hashes:
|
for objectHash in self.hashes:
|
||||||
if current_thread().peer not in self.hashes[hash]:
|
if current_thread().peer not in self.hashes[objectHash]:
|
||||||
self.hashes[hash].append(current_thread().peer)
|
self.hashes[objectHash].append(current_thread().peer)
|
||||||
|
|
||||||
|
|
||||||
def len(self):
|
def len(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user