Skip to content

Use replica for admin PvP stats reads#188

Open
Yehonal wants to merge 1 commit into
azerothcore:masterfrom
Yehonal:chromiecraft/pvpstats-admin-replica
Open

Use replica for admin PvP stats reads#188
Yehonal wants to merge 1 commit into
azerothcore:masterfrom
Yehonal:chromiecraft/pvpstats-admin-replica

Conversation

@Yehonal
Copy link
Copy Markdown
Member

@Yehonal Yehonal commented May 17, 2026

Summary

  • route heavy admin-panel PvP stats read queries through a dedicated replica PDO connection
  • keep reward/account writes on the normal live/write-capable path
  • remove duplicate executeQuery calls in ACoreServices read helpers

Validation

  • php -l passed for SettingsController.php and ACoreServices.php on the production CT checkout before PR packaging

Move heavy PvP stats admin-panel read queries onto a dedicated replica PDO connection while leaving reward/account writes on the normal path. Also remove duplicated executeQuery calls in ACoreServices read helpers.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Routes the admin-panel PvP rewards/statistics read queries through a dedicated replica MySQL connection to reduce load on the primary (write-capable) AzerothCore DB connections, while also cleaning up redundant DBAL statement execution in read helpers.

Changes:

  • Added a PDO-based helper in SettingsController to run PvP stats reads against a replica connection configured via environment variables.
  • Switched the PvP rewards/statistics queries to use the replica query helper instead of the Doctrine character DB connection.
  • Removed redundant duplicate executeQuery() calls in several ACoreServices read helper methods.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/acore-wp-plugin/src/Manager/ACoreServices.php Removes redundant extra executeQuery() calls so read helpers only execute once per request.
src/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php Introduces a replica PDO connection + helper and routes PvP stats reads through it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +44
private function getPvpStatsReplicaPdo(): \PDO {
return new \PDO(
'mysql:host=' . getenv('PVPSTATS_REPLICA_HOST') . ';port=' . getenv('PVPSTATS_REPLICA_PORT') . ';dbname=' . getenv('PVPSTATS_REPLICA_DB') . ';charset=utf8mb4',
getenv('PVPSTATS_REPLICA_USER'),
getenv('PVPSTATS_REPLICA_PASSWORD'),
[
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
]
);
}

private function runPvpStatsReplicaQuery(string $query, array $params): array {
$stmt = $this->getPvpStatsReplicaPdo()->prepare($query);
foreach ($params as $key => $value) {
$stmt->bindValue(':' . $key, $value);
}
$stmt->execute();
return $stmt->fetchAll();
}
Comment on lines +25 to +35
private function getPvpStatsReplicaPdo(): \PDO {
return new \PDO(
'mysql:host=' . getenv('PVPSTATS_REPLICA_HOST') . ';port=' . getenv('PVPSTATS_REPLICA_PORT') . ';dbname=' . getenv('PVPSTATS_REPLICA_DB') . ';charset=utf8mb4',
getenv('PVPSTATS_REPLICA_USER'),
getenv('PVPSTATS_REPLICA_PASSWORD'),
[
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
]
);
}
$conn = $this->getAccountEm()->getConnection();
$stmt = $conn->prepare($query);
$stmt->bindValue(1, $user->get("user_login"));
$stmt->executeQuery();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was not necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants