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

Discovery occurs for all requests, even ones without the Lodata prefix #815

Open
John5 opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@John5
Copy link

John5 commented Apr 24, 2024

While changing code in LodataServiceProvider I noticed that any error there also is thrown on any other route that does not have the Lodata prefix. This means that all the ODP discovery and setup is done for every request. In my case the ODP functionality is being added to an existing monolith so it adds a significant overhead to all requests to existing routes.

I worked around this by adding a check in the boot() method to see if the path of the request matches the configured Lodata prefix like this:

class LodataServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if (!self::isOdpRequest(\Request::path())) {
            return;
        }
        // DO EVERYTHING ELSE
    }

    public static function isOdpRequest(string $path): bool
    {
        $prefix = \Config::get('lodata.prefix');
        return str_starts_with($path, $prefix);
    }
}

I think it is a good idea to add something like this to the Lodata library by default. Otherwise someone else with a similar issue might find this useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant