/// <summary> /// Identify cache dependencies. /// </summary> private static void IdentifyCacheDependencies(Report report, ReportToQueryConverterSettings settings, StructuredQuery query) { // Tell the cache what entities were referenced to return // the StructuredQuery result using (CacheContext cacheContext = CacheContext.GetContext( )) { cacheContext.Entities.Add(report.Id); if (query.Conditions != null) { foreach (var condition in query.Conditions) { cacheContext.Entities.Add(condition.EntityId); if (condition.Expression != null) { cacheContext.Entities.Add(condition.Expression.EntityId); } } } if (query.OrderBy != null) { foreach (var orderBy in query.OrderBy) { if (orderBy.Expression != null) { cacheContext.Entities.Add(orderBy.Expression.EntityId); } } } if (query.SelectColumns != null) { foreach (var column in query.SelectColumns) { cacheContext.Entities.Add(column.EntityId); if (column.Expression != null) { cacheContext.Entities.Add(column.Expression.EntityId); } } } if (report.ReportOrderBys != null) { foreach (var orderBy in report.ReportOrderBys) { if (orderBy != null) { cacheContext.Entities.Add(orderBy.Id); } } } } StructuredQueryHelper.IdentifyStructureCacheDependencies(query, settings.ConditionsOnly); }
/// <summary> /// Check cache dependencies. (Note: wrapped, so we can write tests guaranteeing we have the same implementation) /// </summary> internal static void IdentifyCacheDependencies(StructuredQuery query, QuerySqlBuilderSettings settings) { // Note: if we are suppressing the root type check, then it means that the caller will be joining the query into a larger query. // (I.e. this is a security subquery in a secured report). // If that is the case, then the parent query will already be registering invalidation watches for the type of that node. // So we don't need to further add them for the security query as well. // This is an important optimisation because there are security reports that apply to all resources, and get joined into nodes that // are only for specific resource types. So without ignoring the root, we would basically invalidate every report as part of every entity change. StructuredQueryHelper.IdentifyStructureCacheDependencies(query, false, settings.SuppressRootTypeCheck || settings.SupportRootIdFilter); }