Skip to content

Commit

Permalink
[backend] Filter on empty IDs in lists during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Jan 29, 2025
1 parent 2941a40 commit 7b997f3
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as R from 'ramda';
import { Promise } from 'bluebird';
import { logMigration } from '../config/conf';
import { BULK_TIMEOUT, elBulk, elFindByIds, elList, elUpdateByQueryForMigration, ES_MAX_CONCURRENCY, MAX_BULK_OPERATIONS } from '../database/engine';
import { READ_INDEX_STIX_DOMAIN_OBJECTS } from '../database/utils';
import { isNotEmptyField, READ_INDEX_STIX_DOMAIN_OBJECTS } from '../database/utils';
import { executionContext, SYSTEM_USER } from '../utils/access';
import {
ENTITY_TYPE_CAMPAIGN,
Expand Down Expand Up @@ -37,7 +37,7 @@ export const up = async (next) => {
const threat = threats[i];
const relatedToIds = threat[relKeyRelatedTo] ?? [];
const newIds = [];
const groupIds = R.splitEvery(5000, relatedToIds);
const groupIds = R.splitEvery(5000, relatedToIds.filter((id) => isNotEmptyField(id)));
for (let index = 0; index < groupIds.length; index += 1) {
const workingIds = groupIds[index];
const entitiesBaseData = await elFindByIds(context, SYSTEM_USER, workingIds, { baseData: true });
Expand Down Expand Up @@ -95,7 +95,7 @@ export const up = async (next) => {
const location = locations[i];
const locatedAtIds = location[relKeyLocatedAt] ?? [];
const newIds = [];
const groupIds = R.splitEvery(5000, locatedAtIds);
const groupIds = R.splitEvery(5000, locatedAtIds.filter((id) => isNotEmptyField(id)));
for (let index = 0; index < groupIds.length; index += 1) {
const workingIds = groupIds[index];
const entitiesBaseData = await elFindByIds(context, SYSTEM_USER, workingIds, { baseData: true });
Expand Down

0 comments on commit 7b997f3

Please sign in to comment.