Skip to content

Cleanup performance #1739

@vencakrecl

Description

@vencakrecl

For the project where I use this package, the cleanup process was slow. So, I created this solution which reduced the time from 537s to 17s. It would be nice to integrate the solution into the package.

        $content = $generator?->toYaml() ?? '';

        $stop = false;
        $i = 1;
        while ($stop === false) {
            $matches = [];
            preg_match_all("@'#/components/schemas/(.*)'@", $content, $matches);

            $data = Yaml::parse($content);

            $unset = false;
            foreach ($data['components']['schemas'] as $key => $match) {
                if (!in_array($key, $matches[1])) {
                    unset($data['components']['schemas'][$key]);
                    $unset = true;
                }
            }

            $content = Yaml::dump($data, 10, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_NUMERIC_KEY_AS_STRING);

            if ($unset === false) {
                $stop = true;
            }

            echo "cleaning loop $i";
            $i++;
        }

        file_put_contents(
            filename: sprintf('%s/openapi.yaml', __DIR__),
            data: Yaml::dump($data, 10, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_NUMERIC_KEY_AS_STRING)
        );

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions