prevent sqlite database from locking up

This commit is contained in:
Izalia Mae 2024-02-15 20:26:33 -05:00
parent b86159c7ae
commit b259f2d760

View file

@ -98,17 +98,18 @@ async def handle_follow(view: ActorView, conn: Connection) -> None:
logging.verbose('Non-application actor tried to follow: %s', view.actor.id) logging.verbose('Non-application actor tried to follow: %s', view.actor.id)
return return
if conn.get_inbox(view.actor.shared_inbox): with conn.transaction():
view.instance = conn.update_inbox(view.actor.shared_inbox, followid = view.message.id) if conn.get_inbox(view.actor.shared_inbox):
view.instance = conn.update_inbox(view.actor.shared_inbox, followid = view.message.id)
else: else:
view.instance = conn.put_inbox( view.instance = conn.put_inbox(
view.actor.domain, view.actor.domain,
view.actor.shared_inbox, view.actor.shared_inbox,
view.actor.id, view.actor.id,
view.message.id, view.message.id,
software software
) )
view.app.push_message( view.app.push_message(
view.actor.shared_inbox, view.actor.shared_inbox,
@ -144,12 +145,13 @@ async def handle_undo(view: ActorView, conn: Connection) -> None:
if view.instance['followid'] and view.instance['followid'] != view.message.object_id: if view.instance['followid'] and view.instance['followid'] != view.message.object_id:
return return
if not conn.del_inbox(view.actor.id): with conn.transaction():
logging.verbose( if not conn.del_inbox(view.actor.id):
'Failed to delete "%s" with follow ID "%s"', logging.verbose(
view.actor.id, 'Failed to delete "%s" with follow ID "%s"',
view.message.object['id'] view.actor.id,
) view.message.object['id']
)
view.app.push_message( view.app.push_message(
view.actor.shared_inbox, view.actor.shared_inbox,
@ -182,20 +184,22 @@ async def run_processor(view: ActorView) -> None:
return return
with view.database.connection(True) as conn: with view.database.connection(False) as conn:
if view.instance: if view.instance:
if not view.instance['software']: if not view.instance['software']:
if (nodeinfo := await view.client.fetch_nodeinfo(view.instance['domain'])): if (nodeinfo := await view.client.fetch_nodeinfo(view.instance['domain'])):
view.instance = conn.update_inbox( with conn.transaction():
view.instance['inbox'], view.instance = conn.update_inbox(
software = nodeinfo.sw_name view.instance['inbox'],
) software = nodeinfo.sw_name
)
if not view.instance['actor']: if not view.instance['actor']:
view.instance = conn.update_inbox( with conn.transaction():
view.instance['inbox'], view.instance = conn.update_inbox(
actor = view.actor.id view.instance['inbox'],
) actor = view.actor.id
)
logging.verbose('New "%s" from actor: %s', view.message.type, view.actor.id) logging.verbose('New "%s" from actor: %s', view.message.type, view.actor.id)
await processors[view.message.type](view, conn) await processors[view.message.type](view, conn)