--- id: 88bbf5f1-2d76-4e68-9c62-ca72e464f5c0 type: code_pattern title: "Optional locking parameter pattern for read vs write commands" tags: [paper-dynasty, python, discord-bot, architecture, locking, concurrency, pattern] importance: 0.75 confidence: 0.8 created: "2026-02-04T15:53:57.725265+00:00" updated: "2026-02-04T15:53:57.725265+00:00" relations: - target: 5d8e1ff5-3354-4cfa-ab63-bf96b5ce1e01 type: BUILDS_ON direction: incoming strength: 0.5 --- In Paper Dynasty, added lock_play parameter (default=True) to checks_log_interaction() to distinguish read-only commands from write commands. Read-only commands like /show-card and /settings-ingame use lock_play=False to avoid unnecessary locking. Write commands that modify play state use default lock_play=True. This reduces lock contention and prevents blocking users during non-critical operations. Pattern: Create single validation function with optional locking, rather than duplicating validation logic for read vs write. Also moved actual state modifications to callbacks (dropdown selections) where lock is acquired at last possible moment, keeping commands themselves lock-free. Structure: Command shows UI -> User interaction triggers callback -> Callback acquires lock -> Modifies state -> Releases lock. This minimizes lock hold time.