mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-05 07:04:44 +00:00
fix(searchContext): fix search flag immutability (#10117)
This commit is contained in:
parent
f9e64d03cc
commit
088e7a87d8
1
.github/actions/ci-optimization/action.yml
vendored
1
.github/actions/ci-optimization/action.yml
vendored
@ -70,6 +70,7 @@ runs:
|
||||
- "metadata-jobs/**"
|
||||
- "metadata-service/**"
|
||||
- "metadata-utils/**"
|
||||
- "metadata-operation-context/**"
|
||||
- "datahub-graphql-core/**"
|
||||
- "smoke-test/**"
|
||||
- "docker/**"
|
||||
|
||||
@ -21,10 +21,14 @@ public class SearchContext implements ContextInterface {
|
||||
public static SearchContext withFlagDefaults(
|
||||
@Nonnull SearchContext searchContext,
|
||||
@Nonnull Function<SearchFlags, SearchFlags> flagDefaults) {
|
||||
return searchContext.toBuilder()
|
||||
// update search flags
|
||||
.searchFlags(flagDefaults.apply(searchContext.getSearchFlags()))
|
||||
.build();
|
||||
try {
|
||||
return searchContext.toBuilder()
|
||||
// update search flags
|
||||
.searchFlags(flagDefaults.apply(searchContext.getSearchFlags().copy()))
|
||||
.build();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull private final IndexConvention indexConvention;
|
||||
|
||||
@ -76,4 +76,17 @@ public class SearchContextTest {
|
||||
.getCacheKeyComponent(),
|
||||
"Expected differences in search flags to result in different caches");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImmutableSearchFlags() {
|
||||
SearchContext initial =
|
||||
SearchContext.builder().indexConvention(IndexConventionImpl.NO_PREFIX).build();
|
||||
assertEquals(initial.getSearchFlags(), new SearchFlags().setSkipCache(false));
|
||||
|
||||
SearchContext mutated = initial.withFlagDefaults(flags -> flags.setSkipCache(true));
|
||||
assertEquals(mutated.getSearchFlags(), new SearchFlags().setSkipCache(true));
|
||||
|
||||
// ensure original is not changed
|
||||
assertEquals(initial.getSearchFlags(), new SearchFlags().setSkipCache(false));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user