If you have that many locks in your database you have a serious problem. Use Redis for transactional file locking as said in the first post by @tflidd.
If they are stored in your database you don’t use transactional locking as described here: : Transactional file locking — Nextcloud 13 Administration Manual 13 documentation