/// <summary> /// Loads the cache objects. /// </summary> private void LoadCacheObjects(RockContext rockContext) { // Cache all the entity types foreach (var entityType in new Rock.Model.EntityTypeService(rockContext).Queryable().AsNoTracking()) { EntityTypeCache.Read(entityType); } // Cache all the Field Types foreach (var fieldType in new Rock.Model.FieldTypeService(rockContext).Queryable().AsNoTracking()) { Rock.Web.Cache.FieldTypeCache.Read(fieldType); } var all = Rock.Web.Cache.FieldTypeCache.All(); // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached var qualifiers = new Dictionary <int, Dictionary <string, string> >(); foreach (var attributeQualifier in new Rock.Model.AttributeQualifierService(rockContext).Queryable().AsNoTracking()) { try { if (!qualifiers.ContainsKey(attributeQualifier.AttributeId)) { qualifiers.Add(attributeQualifier.AttributeId, new Dictionary <string, string>()); } qualifiers[attributeQualifier.AttributeId].Add(attributeQualifier.Key, attributeQualifier.Value); } catch (Exception ex) { LogError(ex, null); } } // Cache all the attributes, except for user preferences var attributeQuery = new Rock.Model.AttributeService(rockContext).Queryable("Categories"); int?personUserValueEntityTypeId = Rock.Web.Cache.EntityTypeCache.GetId(Person.USER_VALUE_ENTITY); if (personUserValueEntityTypeId.HasValue) { attributeQuery = attributeQuery.Where(a => !a.EntityTypeId.HasValue || a.EntityTypeId.Value != personUserValueEntityTypeId); } foreach (var attribute in attributeQuery.AsNoTracking().ToList()) { if (qualifiers.ContainsKey(attribute.Id)) { Rock.Web.Cache.AttributeCache.Read(attribute, qualifiers[attribute.Id]); } else { Rock.Web.Cache.AttributeCache.Read(attribute, new Dictionary <string, string>()); } } // cache all the Country Defined Values since those can be loaded in just a few millisecond here, but take around 1-2 seconds if first loaded when formatting an address foreach (var definedValue in new Rock.Model.DefinedValueService(rockContext).GetByDefinedTypeGuid(Rock.SystemGuid.DefinedType.LOCATION_COUNTRIES.AsGuid()).AsNoTracking()) { DefinedValueCache.Read(definedValue, rockContext); } }
/// <summary> /// Loads the cache objects. /// </summary> private static void LoadCacheObjects(RockContext rockContext) { // Cache all the entity types foreach (var entityType in new Rock.Model.EntityTypeService(rockContext).Queryable().AsNoTracking()) { EntityTypeCache.Get(entityType); } // Cache all the Field Types foreach (var fieldType in new Rock.Model.FieldTypeService(rockContext).Queryable().AsNoTracking()) { // improve performance of loading FieldTypeCache by doing LoadAttributes using an existing rockContext before doing FieldTypeCache.Get to avoid calling LoadAttributes with new context per FieldTypeCache fieldType.LoadAttributes(rockContext); FieldTypeCache.Get(fieldType); } var all = FieldTypeCache.All(); // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached var qualifiers = new Dictionary <int, Dictionary <string, string> >(); foreach (var attributeQualifier in new Rock.Model.AttributeQualifierService(rockContext).Queryable().AsNoTracking()) { try { if (!qualifiers.ContainsKey(attributeQualifier.AttributeId)) { qualifiers.Add(attributeQualifier.AttributeId, new Dictionary <string, string>()); } qualifiers[attributeQualifier.AttributeId].Add(attributeQualifier.Key, attributeQualifier.Value); } catch (Exception ex) { var startupException = new RockStartupException("Error loading cache objects", ex); LogError(startupException, null); } } // Cache all the attributes, except for user preferences var attributeQuery = new Rock.Model.AttributeService(rockContext).Queryable("Categories"); int?personUserValueEntityTypeId = EntityTypeCache.GetId(Person.USER_VALUE_ENTITY); if (personUserValueEntityTypeId.HasValue) { attributeQuery = attributeQuery.Where(a => !a.EntityTypeId.HasValue || a.EntityTypeId.Value != personUserValueEntityTypeId); } foreach (var attribute in attributeQuery.AsNoTracking().ToList()) { // improve performance of loading AttributeCache by doing LoadAttributes using an existing rockContext before doing AttributeCache.Get to avoid calling LoadAttributes with new context per AttributeCache attribute.LoadAttributes(rockContext); if (qualifiers.ContainsKey(attribute.Id)) { Rock.Web.Cache.AttributeCache.Get(attribute, qualifiers[attribute.Id]); } else { Rock.Web.Cache.AttributeCache.Get(attribute, new Dictionary <string, string>()); } } // Force authorizations to be cached Rock.Security.Authorization.Get(); }
/// <summary> /// Loads the cache objects. /// </summary> private void LoadCacheObjects( RockContext rockContext ) { // Cache all the entity types foreach ( var entityType in new Rock.Model.EntityTypeService( rockContext ).Queryable().AsNoTracking() ) { EntityTypeCache.Read( entityType ); } // Cache all the Field Types foreach ( var fieldType in new Rock.Model.FieldTypeService( rockContext ).Queryable().AsNoTracking() ) { Rock.Web.Cache.FieldTypeCache.Read( fieldType ); } var all = Rock.Web.Cache.FieldTypeCache.All(); // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached var qualifiers = new Dictionary<int, Dictionary<string, string>>(); foreach ( var attributeQualifier in new Rock.Model.AttributeQualifierService( rockContext ).Queryable().AsNoTracking() ) { try { if ( !qualifiers.ContainsKey( attributeQualifier.AttributeId ) ) { qualifiers.Add( attributeQualifier.AttributeId, new Dictionary<string, string>() ); } qualifiers[attributeQualifier.AttributeId].Add( attributeQualifier.Key, attributeQualifier.Value ); } catch ( Exception ex ) { LogError( ex, null ); } } // Cache all the attributes, except for user preferences var attributeQuery = new Rock.Model.AttributeService( rockContext ).Queryable( "Categories" ); int? personUserValueEntityTypeId = Rock.Web.Cache.EntityTypeCache.GetId( Person.USER_VALUE_ENTITY ); if (personUserValueEntityTypeId.HasValue) { attributeQuery = attributeQuery.Where(a => !a.EntityTypeId.HasValue || a.EntityTypeId.Value != personUserValueEntityTypeId); } foreach ( var attribute in attributeQuery.AsNoTracking().ToList() ) { if ( qualifiers.ContainsKey( attribute.Id ) ) Rock.Web.Cache.AttributeCache.Read( attribute, qualifiers[attribute.Id] ); else Rock.Web.Cache.AttributeCache.Read( attribute, new Dictionary<string, string>() ); } // cache all the Country Defined Values since those can be loaded in just a few millisecond here, but take around 1-2 seconds if first loaded when formatting an address foreach ( var definedValue in new Rock.Model.DefinedValueService( rockContext ).GetByDefinedTypeGuid( Rock.SystemGuid.DefinedType.LOCATION_COUNTRIES.AsGuid() ).AsNoTracking() ) { DefinedValueCache.Read( definedValue, rockContext ); } }