resolve static method
Resolve a vanity slug — fires ALL queries in parallel, returns the highest-priority match.
With 5 sequential queries each taking ~200ms, the old approach took up to 1s worst case. Parallel resolution completes in ~200ms.
Implementation
static Future<SlugMatch?> resolve(String slug) async {
if (slug.isEmpty) return null;
AppConfig.logger.d('SlugRouter: resolving "$slug" across ${_routes.length} routes (parallel)');
// Fire all queries simultaneously
final futures = _routes.map((route) => route.resolve(slug));
final results = await Future.wait(futures);
// Collect non-null matches
final matches = <SlugMatch>[];
for (int i = 0; i < results.length; i++) {
if (results[i] != null) {
matches.add(results[i]!);
}
}
if (matches.isEmpty) {
AppConfig.logger.d('SlugRouter: no match for "$slug"');
return null;
}
// Return highest priority (lowest number) match
if (matches.length > 1) {
AppConfig.logger.w('SlugRouter: ${matches.length} matches for "$slug": '
'${matches.map((m) => m.type).join(", ")}. Using highest priority.');
}
// matches are already ordered by _routes priority since we iterated in order
final match = matches.first;
AppConfig.logger.i('SlugRouter: resolved "$slug" → ${match.type} (${match.id})');
return match;
}