Unverified Commit 1d9e127e authored by Alex Pott's avatar Alex Pott
Browse files

perf: #3586654 Avoid scanning the file system for local po files

By: webflo
By: ishani patel
By: nicxvan
By: andypost
By: penyaskito
By: berdir
parent d43dcd72
Loading
Loading
Loading
Loading
Loading
+4 −11
Original line number Diff line number Diff line
@@ -107,19 +107,12 @@ public function buildSources(array $projects, array $langcodes = []): array {
  public function sourceCheckFile($source) {
    if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) {
      $source_file = $source->files[LOCALE_TRANSLATION_LOCAL];
      $directory = $source_file->directory;
      $filename = '/' . preg_quote($source_file->filename) . '$/';

      if (is_dir($directory)) {
        if ($files = $this->fileSystem->scanDirectory($directory, $filename, ['key' => 'name', 'recurse' => FALSE])) {
          $file = current($files);
          $source_file->uri = $file->uri;
          $source_file->timestamp = filemtime($file->uri);
          $source_file->hash = hash_file(self::LOCAL_FILE_HASH_ALGO, $file->uri);
      if (isset($source_file->uri) && file_exists($source_file->uri)) {
        $source_file->timestamp = filemtime($source_file->uri);
        $source_file->hash = hash_file(self::LOCAL_FILE_HASH_ALGO, $source_file->uri);
        return $source_file;
      }
    }
    }
    return FALSE;
  }