Skip to content

Don't read entire file to improve performance #2

@danieliser

Description

@danieliser

The line below loads what could be a heavy file into memory.

https://github.com/coenjacobs/conductor/blob/master/src/FileReader.php#L9

The way WP core does it is likely more ideal, so we should either patch it to use the get_plugin_data function, or mimic it's functionality.

Specifically, core only loads the first 8 bytes of the file or so via get_file_data.

Option 1

    public function getPluginVersion($slug)
    {
        $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $slug, false, false );
        return ! empty( $data['Version'] ) ? $data['Version'] : false; // Set default that you are set to handle as a false.
    }

Option 2 - A little lighter as it has none of the overhead logic.

    public function getPluginVersion($slug)
    {
        // Stripped down list of headers.
	$default_headers = [
		'Version'     => 'Version',
	];

	$plugin_data = get_file_data( $WP_PLUGIN_DIR . '/' . $slug, $default_headers, 'plugin' );
        return ! empty( $data['Version'] ) ? $data['Version'] : false; // Set default that you are set to handle as a false.
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions