Skip to content
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

Do not perform VACUUM on SQLITE database when clearing system cache? #161

Open
yjmtmtk opened this issue Oct 4, 2023 · 0 comments
Open

Comments

@yjmtmtk
Copy link

yjmtmtk commented Oct 4, 2023

$app->on('app.system.cache.flush', function() use ($app) {
    $data_dir = $app->paths['#storage'][0] . 'data';
    $backup_dir = $data_dir . '_backup';
    if (!file_exists($backup_dir)) {
        mkdir($backup_dir, 0777, true);
    }
    $files = glob($data_dir . '/*.sqlite');
    foreach ($files as $file) {
        try {
            $backup_file = $backup_dir . '/' . basename($file) . '.backup';
            copy($file, $backup_file);
            $db = new SQLite3($file);
            $result = $db->exec('VACUUM');
            $db->close();
            if ($result === false) {
                copy($backup_file, $file);
            }
            unlink($backup_file);
        } catch (Exception $e) {
            
        }
    }
    if (is_dir($backup_dir)) {
        $backup_files = glob($backup_dir . '/*');
        foreach ($backup_files as $file) {
            unlink($file);
        }
        rmdir($backup_dir);
    }
});

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

No branches or pull requests

1 participant