Single-Query Bootstrap and Performance

The Problem with Redundant Queries

Traditional MVC systems query the database repeatedly on startup: once to fetch active site configs, once to load the active session, once to load user roles, and once to read preferences. This creates massive blocking network latency and round-trip splits.

Consolidated SQL UNION Handshake

Zero CMS resolves this dynamically by compiling both the active Site Tenant and the logged-in User inside a single SQL UNION transaction on startup:

Consolidated UNION SQL Query

Consolidated UNION SQL Query php
$sql = "
    SELECT 
        'site' AS record_type, id, name, domain, theme, enabled_modules,
        NULL AS email, NULL AS password_hash, NULL AS role, NULL AS site_id, NULL AS preferences,
        created_at, updated_at 
    FROM sites WHERE domain = ?
    UNION ALL
    SELECT 
        'user' AS record_type, id, username AS name, NULL AS domain, NULL AS theme, NULL AS enabled_modules,
        email, password_hash, role, site_id, preferences,
        created_at, updated_at 
    FROM users WHERE id = ?
";

In exactly one round-trip, the PDO driver fetches both records, and the bootstrapper instantiates the model objects inside memory immediately!

Static Latch Singleton Lock

To prevent redundant boots during sub-route renders or controllers iterations, a static $bootstrapped latch flag acts as a singleton guard, blocking duplicate SQL trips during a single request lifecycle.