Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila committed Jul 4, 2023
1 parent dfe8316 commit 3ba6b03
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { buildPickupMappingsQuery } from './build_pickup_mappings_query';
describe('buildPickupMappingsQuery', () => {
describe('when no root fields have been updated', () => {
it('builds a boolean query to select the updated types', () => {
const query = buildPickupMappingsQuery({
rootFields: ['someRootField'],
updatedFields: ['type1', 'type2'],
});
const query = buildPickupMappingsQuery(['type1', 'type2']);

expect(query).toEqual({
bool: {
Expand All @@ -26,10 +23,7 @@ describe('buildPickupMappingsQuery', () => {

describe('when some root fields have been updated', () => {
it('returns undefined', () => {
const query = buildPickupMappingsQuery({
rootFields: ['someRootField'],
updatedFields: ['type1', 'type2', 'someRootField'],
});
const query = buildPickupMappingsQuery(['type1', 'type2', 'namespaces']);

expect(query).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/

import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { getBaseMappings } from './build_active_mappings';

export const buildPickupMappingsQuery = (
updatedFields: string[]
): QueryDslQueryContainer | undefined => {
const rootFields = Object.keys(getBaseMappings().properties);

export const buildPickupMappingsQuery = ({
rootFields,
updatedFields,
}: {
rootFields: string[];
updatedFields: string[];
}): QueryDslQueryContainer | undefined => {
if (updatedFields.some((field) => rootFields.includes(field))) {
// we are updating some root fields, update ALL documents (no filter query)
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,9 +1443,7 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
} else if (isTypeof(left, 'compared_mappings_changed')) {
const rootFields = Object.keys(getBaseMappings().properties);
const updatedRootFields = left.updatedHashes.filter((field) => rootFields.includes(field));
const updatedTypesQuery = Option.fromNullable(
buildPickupMappingsQuery({ rootFields, updatedFields: left.updatedHashes })
);
const updatedTypesQuery = Option.fromNullable(buildPickupMappingsQuery(left.updatedHashes));

if (updatedRootFields.length) {
// compatible migration: some core fields have been updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
setMetaDocMigrationStarted,
} from './utils';
import { buildPickupMappingsQuery } from '../core/build_pickup_mappings_query';
import { getBaseMappings } from '../core';

export type ActionMap = ReturnType<typeof nextActionMap>;

Expand Down Expand Up @@ -74,10 +73,7 @@ export const nextActionMap = (context: MigratorContext) => {
index: state.currentIndex,
mappings: { properties: state.additiveMappingChanges },
batchSize: context.batchSize,
query: buildPickupMappingsQuery({
rootFields: Object.keys(getBaseMappings().properties),
updatedFields: Object.keys(state.additiveMappingChanges),
}),
query: buildPickupMappingsQuery(Object.keys(state.additiveMappingChanges)),
}),
UPDATE_INDEX_MAPPINGS_WAIT_FOR_TASK: (state: UpdateIndexMappingsWaitForTaskState) =>
Actions.waitForPickupUpdatedMappingsTask({
Expand Down

0 comments on commit 3ba6b03

Please sign in to comment.