An SQL query keeps locking the database

I would start digging into this point. Verify if this table contains obsolete entries. This could happen if you had external storage in the past, moved data directory etc. If multiple user mount the same external storage like SMB individually files appear multiplied.

we had quite few discussions about oc_filecache size and e.g. How to shrink oc_filecache (440GB, vs 360GB files hosted) review and check if you find any obvious problem like files on old storages still stored in the tables and try to recover.