https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43523

--- Comment #12 from Paul Derscheid <[email protected]> ---
Hi Lucas, good stuff.

Here's some more stuff I found while testing this but should probably be a
follow-up if we want to take this further.

---

What follows was written by Claude Opus 5.5.

Some numbers from QA on bug 43523 (KTD, BorrowersLog on, per patron,
measured in rolled-back transactions):

- Raw SQL DELETE incl. FK cascades: 0.28 ms
- Koha::Patron->delete: 8.2 ms (5.7 ms with BorrowersLog off)
  - Holds/lists/modifications checks: ~2.5 ms, even when there is
    nothing to clean up
  - BorrowersLog payload (attributes, permissions): ~2.5 ms
- find + move_to_deleted in the cleanborrowers.pl loop: ~3 ms

So the time goes into per-patron ORM work, not the database.

Suggestions:

1. Replace the find/move_to_deleted/delete loop with the existing
   set-level API, as cleanup_database.pl already does:

     Koha::Patrons->search( { borrowernumber => \@ids } )
         ->delete( { move => $radio eq 'trash' } );

   ~20% faster (9.7 -> 7.9 ms/patron), and it avoids
   "Can't call method "delete" on an undefined value" when two
   requests run concurrently (rows already deleted drop out of the set).
   It runs in a single transaction, so a background job should
   probably chunk it.

2. The background job itself is the real fix: at ~8 ms/patron, 100k
   patrons is still ~13 minutes, far beyond an HTTP request.

3. A larger speedup would need set-based pre-checks in
   Koha::Patron->delete (one query for which candidates have
   holds/lists/modifications), but that is a separate refactor.

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to