Skip to content

Commit f91fb15

Browse files
alfsbkamil-tekiela
andauthored
Faster file listing (#236)
* Faster file listing * Review. Co-authored-by: Kamil Tekiela <[email protected]>
1 parent 281ee98 commit f91fb15

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

scripts/translation/libqa/SyncFileList.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,39 @@ static function load()
3131
}
3232

3333
$lang = trim( file_get_contents( $file ) );
34-
$cache = __DIR__ . "/../../../temp/qaxml.files.$lang";
34+
$cacheFilename = __DIR__ . "/../../../temp/qaxml.files.$lang";
3535

36-
if ( file_exists( $cache ) )
36+
if ( file_exists( $cacheFilename ) )
3737
{
38-
$data = file_get_contents( $cache );
39-
return unserialize( gzdecode( $data ) );
38+
return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) );
4039
}
4140

41+
$sourceDir = 'en';
42+
$targetDir = $lang;
43+
4244
require_once __DIR__ . '/../lib/all.php';
4345

44-
$revcheck = new RevcheckRun( 'en' , $lang );
45-
$revdata = $revcheck->revData;
46-
$list = [];
46+
$files = new RevcheckFileList( $sourceDir );
47+
$syncFileItems = [];
4748

48-
foreach( $revdata->fileDetail as $file )
49+
foreach( $files->iterator() as $file )
4950
{
50-
$source = "{$revcheck->sourceDir}/{$file->path}/{$file->name}";
51-
$target = "{$revcheck->targetDir}/{$file->path}/{$file->name}";
52-
53-
if ( ! file_exists( $source ) )
54-
continue;
55-
if ( ! file_exists( $target ) )
51+
if ( ! file_exists( "$targetDir/{$file->file}" ) )
5652
continue;
5753

5854
$item = new SyncFileItem();
59-
$item->sourceDir = $revcheck->sourceDir;
60-
$item->targetDir = $revcheck->targetDir;
61-
$item->file = $file->path . '/' . $file->name;
62-
$list[] = $item;
55+
$item->sourceDir = $sourceDir;
56+
$item->targetDir = $targetDir;
57+
$item->file = $file->file;
58+
$ret[] = $item;
6359
}
6460

65-
if ( count( $list ) == 0 )
61+
if ( $syncFileItems === [] )
6662
throw new Exception( "No files found. Called from wrong directory?" );
6763

68-
$contents = gzencode( serialize( $list ) );
69-
file_put_contents( $cache , $contents );
64+
$contents = gzencode( serialize( $ret ) );
65+
file_put_contents( $cacheFilename , $contents );
7066

71-
return $list;
67+
return $ret;
7268
}
7369
}

0 commit comments

Comments
 (0)