/// <summary> /// Verify that a relationship is under the necessary fanout limit. /// </summary> /// <param name="relReq"></param> /// <param name="entityId"></param> /// <param name="relCount"></param> internal static void CheckFanoutLimit(RelationshipRequest relReq, long entityId, int relCount) { string prefix = null; bool isError = false; int threshold = MaxRelatedEntitiesWarning; // Warning or error? if (relCount > MaxRelatedEntitiesWarning && !EntityDataBuilder <IEntity> .BypassMaxRelatedEntities(relReq, entityId)) { prefix = "Large number"; if (relCount > MaxRelatedEntities) { isError = true; prefix = "Exceeded maximum number"; threshold = MaxRelatedEntities; } } // All OK if (prefix == null) { return; } // Format message string message = string.Format( "{0} ({1} > {2}) of related entities for EntityInfoService. Relationship: {3} {4}. {5} entity: {6} {7}\n{8}", prefix, relCount, threshold, relReq.RelationshipTypeId, Entity.GetNameForLogEntry(relReq.RelationshipTypeId.Id), relReq.IsReverse ? "To" : "From", entityId, Entity.GetNameForLogEntry(entityId), Environment.StackTrace ); if (isError) { EventLog.Application.WriteError(message); } else { EventLog.Application.WriteWarning(message); } }
/// <summary> /// Return true if we should special-case bypass the max fanout limit. /// </summary> /// <remarks> /// Ordinarily we really want to lock down the fanout. But there's already too much code that /// relies on following 'derivedTypes' from resource, which is too many. TODO: Fix this one day. /// </remarks> /// <returns>True to bypass, otherwise false.</returns> internal static bool BypassMaxRelatedEntities(RelationshipRequest request, long originEntityId) { // only bypass core:derivedTypes in the forward direction. (noting that the alias itself is reverse .. but we are following the reverse alias forwards) if (request.RelationshipTypeId.Alias != "derivedTypes" || request.RelationshipTypeId.Namespace != "core" || request.IsReverse) { return(false); } // only bypass if we're coming from core:resource IEntity entity = Entity.Get(originEntityId); if (entity == null) { return(false); } bool result = entity.Alias == "resource" && entity.Namespace == "core"; return(result); }