Skip to content

cfmigrations runs hundreds of duplicate SQL queries on app init #34

@michaelborn

Description

@michaelborn

Running migrationService.hasMigrationsToRun( "up" ) to check for migrations to run causes cfmigrations to run a SQL query for every migration cfc in the migrations directory. So if you have a large app with hundreds or thousands of migrations, cfmigrations will run SELECT name from cfmigrations hundreds or thousands of times!

To fix this, we should cache the query results in the variables scope:

https://github.com/coldbox-modules/cfmigrations/blob/v2.0.10/models/MigrationService.cfc#L311-L318

var migrations = queryExecute(
    "
        SELECT name
        FROM #getMigrationsTable()#
    ",
    {},
    { datasource : getDatasource() }
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions