Skip to content

Faster file listing #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions scripts/translation/libqa/SyncFileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,39 @@ static function load()
}

$lang = trim( file_get_contents( $file ) );
$cache = __DIR__ . "/../../../temp/qaxml.files.$lang";
$cacheFilename = __DIR__ . "/../../../temp/qaxml.files.$lang";

if ( file_exists( $cache ) )
if ( file_exists( $cacheFilename ) )
{
$data = file_get_contents( $cache );
return unserialize( gzdecode( $data ) );
return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) );
}

$sourceDir = 'en';
$targetDir = $lang;

require_once __DIR__ . '/../lib/all.php';

$revcheck = new RevcheckRun( 'en' , $lang );
$revdata = $revcheck->revData;
$list = [];
$files = new RevcheckFileList( $sourceDir );
$syncFileItems = [];

foreach( $revdata->fileDetail as $file )
foreach( $files->iterator() as $file )
{
$source = "{$revcheck->sourceDir}/{$file->path}/{$file->name}";
$target = "{$revcheck->targetDir}/{$file->path}/{$file->name}";

if ( ! file_exists( $source ) )
continue;
if ( ! file_exists( $target ) )
if ( ! file_exists( "$targetDir/{$file->file}" ) )
continue;

$item = new SyncFileItem();
$item->sourceDir = $revcheck->sourceDir;
$item->targetDir = $revcheck->targetDir;
$item->file = $file->path . '/' . $file->name;
$list[] = $item;
$item->sourceDir = $sourceDir;
$item->targetDir = $targetDir;
$item->file = $file->file;
$ret[] = $item;
}

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

$contents = gzencode( serialize( $list ) );
file_put_contents( $cache , $contents );
$contents = gzencode( serialize( $ret ) );
file_put_contents( $cacheFilename , $contents );

return $list;
return $ret;
}
}