Welcome Guest, Not a member yet? Register   Sign In
Many, many routes - performance penalties?
#1

(This post was last modified: 08-19-2020, 01:45 AM by tgix.)

Don't know if this a cause for concern or just me overthinking stuff.
In my back-end project for a large administrative site I have started to fill up the Routes.php file with routes for each individual path into the system. Using groups really help, but I am still worried about the scalability of this since setting up the routes happens for each request and setting up the routes requires code to be executed. Some of the functions in the routes generation process are quite complex.

Currently my routes are setup with (and this is about 10% into the project...):

PHP Code:
// Generic Pickers
$routes->options('picker/(.+)''Options::index');
$routes->get('picker/(:any)''Pickers::$1', ['filter' => 'bearer-auth:all']);

// Images for various items
$routes->options('images/(.+)''Options::index', ['filter' => 'bearer-auth:all']);
$routes->get('images/(:segment)/(:segment)''Images::$1/$2', ['filter' => 'bearer-auth:all']);

/**
 * Verb    | Method name
 * --------| ----------------------------
 * PUT     | update($id)
 *
 */

// Create the config routes for the REST items
$routes->options('config/(.+)''Options::index');
$routes->group('config', ['except' => ['new''edit'], 'filter' => 'bearer-auth:conf'], function ($routes) {

    $routes->get('(:segment)/(:segment)/changehistory''config\Changehistory::$1/$2');

    $routes->resource('credits', ['controller' => 'config\Credits']);

    // Routes for certifications
    $routes->options('certifications/(:segment)/logo''Options::index');
    $routes->post('certifications/(:segment)/logo''config\Certifications::postCertLogo/$1');
    $routes->post('certifications/(:segment)/icon''config\Certifications::postCertIcon/$1');
    $routes->delete('certifications/(:segment)/logo''config\Certifications::deleteCertLogo/$1');
    $routes->delete('certifications/(:segment)/icon''config\Certifications::deleteCertIcon/$1');

    $routes->get('certifications/(:segment)/exams''config\Certifications::getCertExams/$1');
    $routes->get('certifications/(:segment)/issuedcerts''config\Certifications::getIssuedCerts/$1');
    $routes->get('certifications/(:segment)/certversions''config\Certifications::getCertVersions/$1');
    $routes->get('certifications/(:segment)/certverdownload/(:segment)''config\Certifications::getCertVerDownload/$1/$2');

    $routes->put('certifications/(:segment)/certversions/(:segment)''config\Certifications::updateCertVersion/$1/$2');
    $routes->delete('certifications/(:segment)/certversions/(:segment)''config\Certifications::deleteCertVersion/$1/$2');
    $routes->post('certifications/(:segment)/certversions''config\Certifications::createCertVersion/$1');
    $routes->resource('certifications', ['controller' => 'config\Certifications']);

}); 

As optimization I was think along the lines of serializing the routes and being able to simply unserialize() the defined set of routes. Routes aren't likely to change after they have been created in code, are they?

If anyone see any obvious simplifications, I'm all ears!

/Mattias
Reply




Theme © iAndrew 2016 - Forum software by © MyBB