Handle sqlite3 exceptions in __setitem__ instead of checking presence
This commit is contained in:
parent
5aeb0157fc
commit
59fdb7ad77
|
@ -477,7 +477,7 @@ class Connection(ConnectionBase):
|
||||||
logging.debug('%s:%s -> %s', self.host_print, self.port, obj)
|
logging.debug('%s:%s -> %s', self.host_print, self.port, obj)
|
||||||
self.vectors_requested.pop(obj.vector, None)
|
self.vectors_requested.pop(obj.vector, None)
|
||||||
self.vectors_to_get.discard(obj.vector)
|
self.vectors_to_get.discard(obj.vector)
|
||||||
if obj.is_valid() and obj.vector not in shared.objects:
|
if obj.is_valid():
|
||||||
shared.objects[obj.vector] = obj
|
shared.objects[obj.vector] = obj
|
||||||
if (
|
if (
|
||||||
obj.object_type == shared.i2p_dest_obj_type
|
obj.object_type == shared.i2p_dest_obj_type
|
||||||
|
|
|
@ -134,11 +134,14 @@ class Inventory():
|
||||||
|
|
||||||
def __setitem__(self, vector, obj):
|
def __setitem__(self, vector, obj):
|
||||||
with shared.objects_lock:
|
with shared.objects_lock:
|
||||||
|
try:
|
||||||
cur = self._db.execute(
|
cur = self._db.execute(
|
||||||
'INSERT INTO objects VALUES (?,?,?,?,?,?,?,?)', (
|
'INSERT INTO objects VALUES (?,?,?,?,?,?,?,?)', (
|
||||||
vector, obj.expires_time, obj.object_type, obj.version,
|
vector, obj.expires_time, obj.object_type, obj.version,
|
||||||
obj.stream_number, obj.tag, obj.data, obj.offset
|
obj.stream_number, obj.tag, obj.data, obj.offset
|
||||||
))
|
))
|
||||||
|
except (sqlite3.DatabaseError, sqlite3.IntegrityError):
|
||||||
|
return
|
||||||
self._db.commit()
|
self._db.commit()
|
||||||
self.rowid = cur.lastrowid
|
self.rowid = cur.lastrowid
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user