Skip to content

Commit

Permalink
ENH Only query primary DB
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 24, 2024
1 parent bba7c4f commit 16e754e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": "^8.1",
"silverstripe/framework": "^5"
"silverstripe/framework": "^5.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
Expand Down
5 changes: 5 additions & 0 deletions src/Model/HybridSessionDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ class HybridSessionDataObject extends DataObject
];

private static $table_name = 'HybridSessionDataObject';

/**
* Only use the primary db to ensure there is no risk of reading from an unsynced replica db
*/
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 16e754e

Please sign in to comment.