Commit 58da6ca
committed
fix(sessions): skip unnecessary FOR UPDATE lock on app/user state rows
DatabaseSessionService.append_event() unconditionally acquires SELECT ...
FOR UPDATE on both app_states and user_states tables, even when the event
carries no state delta for those scopes.
Since app_states is keyed by app_name alone, all concurrent append_event
calls within the same app serialize on this single row lock, even when
they only carry session-scoped state (the vast majority of events).
Fix: pre-analyze the event's state_delta before acquiring locks and only
use FOR UPDATE when the corresponding scope actually has changes. This
also avoids a redundant call to extract_state_delta later in the method.
Fixes #46551 parent 8ddddc0 commit 58da6ca
1 file changed
Lines changed: 18 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
553 | 567 | | |
554 | 568 | | |
555 | 569 | | |
556 | 570 | | |
557 | | - | |
| 571 | + | |
558 | 572 | | |
559 | 573 | | |
560 | 574 | | |
| |||
568 | 582 | | |
569 | 583 | | |
570 | 584 | | |
571 | | - | |
| 585 | + | |
572 | 586 | | |
573 | 587 | | |
574 | 588 | | |
| |||
599 | 613 | | |
600 | 614 | | |
601 | 615 | | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
| 616 | + | |
| 617 | + | |
607 | 618 | | |
608 | 619 | | |
609 | 620 | | |
| |||
0 commit comments