* Recursively maps optimized subqueries to their original queries for proper caching. * This ensures that when we encounter the same QueryRef object in different contexts, * we can find the original query to check the cache.
( optimizedQuery: QueryIR, originalQuery: QueryIR, queryMapping: QueryMapping, )
| 1476 | * we can find the original query to check the cache. |
| 1477 | */ |
| 1478 | function mapNestedQueries( |
| 1479 | optimizedQuery: QueryIR, |
| 1480 | originalQuery: QueryIR, |
| 1481 | queryMapping: QueryMapping, |
| 1482 | ): void { |
| 1483 | mapNestedFromQueries(optimizedQuery.from, originalQuery.from, queryMapping) |
| 1484 | |
| 1485 | // Map JOIN clauses if they exist |
| 1486 | if (optimizedQuery.join && originalQuery.join) { |
| 1487 | for ( |
| 1488 | let i = 0; |
| 1489 | i < optimizedQuery.join.length && i < originalQuery.join.length; |
| 1490 | i++ |
| 1491 | ) { |
| 1492 | const optimizedJoin = optimizedQuery.join[i]! |
| 1493 | const originalJoin = originalQuery.join[i]! |
| 1494 | |
| 1495 | if ( |
| 1496 | optimizedJoin.from.type === `queryRef` && |
| 1497 | originalJoin.from.type === `queryRef` |
| 1498 | ) { |
| 1499 | queryMapping.set(optimizedJoin.from.query, originalJoin.from.query) |
| 1500 | // Recursively map nested queries in joins |
| 1501 | mapNestedQueries( |
| 1502 | optimizedJoin.from.query, |
| 1503 | originalJoin.from.query, |
| 1504 | queryMapping, |
| 1505 | ) |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | function getRefFromAlias( |
| 1512 | query: QueryIR, |
no test coverage detected