Skip to content

Commit 5b4aeee

Browse files
committed
Move expensive SatisfiesAttributeFilters() call to end of loop
The `SatisfiesAttributeFilters()` call should be reasonably fast, but it's expensive compared to the other validation checks in the `PopulateTargetCollectionAsync()` loop, and there's no need to call it if we can easily reject adding a topic because it violates the `ContentTypeFilter`, is a `List`, or `IsDisabled`. In practice, the most significant impact we'd expect here would be if `[FilterByAttribute()]` is combined with `[FilterByContentType()]`. These used to be the same filter, but since the content type was moved out of attributes, a new filter attribute needed to be introduced. There's no sense in evaluating the attributes if the content type isn't valid.
1 parent e93d1f6 commit 5b4aeee

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,26 +921,27 @@ MappedTopicCache cache
921921

922922
foreach (var childTopic in sourceList) {
923923

924-
//Ensure the source topic matches any [FilterByAttribute()] settings
925-
if (!configuration.SatisfiesAttributeFilters(childTopic)) {
924+
//Ensure the source topic isn't disabled; disabled topics should never be returned to the presentation layer unless
925+
//explicitly requested by a top-level request.
926+
if (childTopic.IsDisabled) {
927+
continue;
928+
}
929+
930+
//Skip nested topics; those should be explicitly mapped to their own collection or topic reference
931+
if (childTopic.ContentType.Equals("List", StringComparison.OrdinalIgnoreCase)) {
926932
continue;
927933
}
928934

935+
//Ensure the source topic matches any [FilterByContentType()] settings
929936
if (
930937
configuration.ContentTypeFilter is not null &&
931938
!childTopic.ContentType.Equals(configuration.ContentTypeFilter, StringComparison.OrdinalIgnoreCase)
932939
) {
933940
continue;
934941
}
935942

936-
//Skip nested topics; those should be explicitly mapped to their own collection or topic reference
937-
if (childTopic.ContentType.Equals("List", StringComparison.OrdinalIgnoreCase)) {
938-
continue;
939-
}
940-
941-
//Ensure the source topic isn't disabled; disabled topics should never be returned to the presentation layer unless
942-
//explicitly requested by a top-level request.
943-
if (childTopic.IsDisabled) {
943+
//Ensure the source topic matches any [FilterByAttribute()] settings
944+
if (!configuration.SatisfiesAttributeFilters(childTopic)) {
944945
continue;
945946
}
946947

0 commit comments

Comments
 (0)