Unverified Commit 19ac1126 authored by Stefan Auditor's avatar Stefan Auditor Committed by Stefan Auditor
Browse files

Issue #3282696 by sanduhrs: Port of l10n_community: Add statistics service

parent 288a643c
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\l10n_server\Entity\L10nServerProjectInterface;
/**
 * Service description.
 *
 * @todo
 * @todo Fix mysql performance problems.
 * These queries are *slooow*. The query cache helps a lot with caching the
 * result, so the slowness only shows for the first run, but still it would be
 * good to look into optimizing these.
@@ -68,10 +68,11 @@ class L10nStatistics {
  /**
   * Get summaries based on language codes.
   *
   * @param L10nServerProjectInterface|null $project
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $project
   *   A l10n_server_project entity.
   *
   * @return array
   *   An array containing translation and suggestion counts.
   */
  public function getLanguagesStringCount(L10nServerProjectInterface $project = NULL): array {
    $sums = [];
@@ -85,7 +86,7 @@ class L10nStatistics {
      // More complex joins if we also need to factor the project in.
      $count1_sql = "SELECT COUNT(DISTINCT ts.sid) AS translation_count, ts.language FROM {l10n_server_line} l INNER JOIN {l10n_server_status_flag} ts ON l.sid = ts.sid WHERE l.pid = :pid AND ts.has_translation = 1 GROUP BY ts.language";
      $count2_sql = "SELECT COUNT(DISTINCT ts.sid) AS translation_count, ts.language FROM {l10n_server_line} l INNER JOIN {l10n_server_status_flag} ts ON l.sid = ts.sid WHERE l.pid = :pid AND ts.has_suggestion = 1 GROUP BY ts.language";
      $count_args = array(':pid' => $project->id());
      $count_args = [':pid' => $project->id()];
    }
    $result = $this->connection->query($count1_sql, $count_args);
    foreach ($result as $row) {
@@ -115,6 +116,7 @@ class L10nStatistics {
    // Get the count of distinct strings having translations and suggestions per
    // project. This is run per project because big installs of the module were
    // choking on GROUP BY based solutions.
    // phpcs:ignore
    foreach (['translations' => 'has_translation', 'suggestions' => 'has_suggestion'] as $key => $column) {
      foreach ($sums as $pid => &$data) {
        $count_args = [];