Skip to content

Commit

Permalink
Merge pull request #114 from creative-commoners/pulls/3/db-replica
Browse files Browse the repository at this point in the history
ENH Only query primary DB
  • Loading branch information
GuySartorelli authored Oct 10, 2024
2 parents c7efcfe + 171cd07 commit 760b5de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Model/HybridSessionDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ class HybridSessionDataObject extends DataObject
];

private static $table_name = 'HybridSessionDataObject';

/**
* Ensure there is no risk of reading from an unsynced database replica so
* that session data is always up to date.
*/
private static bool $must_use_primary_db = true;
}
2 changes: 1 addition & 1 deletion src/Store/DatabaseStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function read(string $session_id): string|false
$this->getNow()
);

$result = DB::query($query);
$result = DB::withPrimary(fn() => DB::query($query));

if ($result && $result->numRecords()) {
$data = $result->record();
Expand Down

0 comments on commit 760b5de

Please sign in to comment.