Skip to content

Commit

Permalink
Merge pull request #3541 from OriginTrail/v8/query-both-new-and-old-r…
Browse files Browse the repository at this point in the history
…epos-while-migration

Query both new and old repos while migration
  • Loading branch information
Mihajlo-Pavlovic authored Dec 19, 2024
2 parents 7124a22 + d7cb03b commit b23b51d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/commands/query/query-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class QueryCommand extends Command {
// query = query.replace(repositoryInOriginalQuery, federatedQueryRepositoryName);
// }
// }

try {
switch (queryType) {
case QUERY_TYPES.CONSTRUCT: {
Expand All @@ -66,7 +67,19 @@ class QueryCommand extends Command {
OPERATION_ID_STATUS.QUERY.QUERY_SELECT_QUERY_START,
operationId,
);
data = await this.tripleStoreService.select(query, repository);

if (Array.isArray(repository)) {
const dataV6 = await this.tripleStoreService.select(query, repository[0]);
const dataV8 = await this.tripleStoreService.select(query, repository[1]);

data = this.dataService.removeDuplicateObjectsFromArray([
...dataV6,
...dataV8,
]);
} else {
data = await this.tripleStoreService.select(query, repository);
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.QUERY.QUERY_SELECT_QUERY_END,
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class QueryController extends BaseController {
queryType,
repository:
!tripleStoreMigrationAlreadyExecuted && repository
? repository
? [repository, TRIPLE_STORE_REPOSITORIES.DKG]
: TRIPLE_STORE_REPOSITORIES.DKG,
operationId,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class QueryController extends BaseController {
queryType,
repository:
!tripleStoreMigrationAlreadyExecuted && repository
? repository
? [repository, TRIPLE_STORE_REPOSITORIES.DKG]
: TRIPLE_STORE_REPOSITORIES.DKG,
operationId,
},
Expand Down
12 changes: 12 additions & 0 deletions src/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ class DataService {
array.splice(left, 0, str);
return left;
}

removeDuplicateObjectsFromArray(array) {
const seen = new Set();
return array.filter((item) => {
const key = Object.values(item).join('_');
if (seen.has(key)) {
return false;
}
seen.add(key);
return true;
});
}
}

export default DataService;

0 comments on commit b23b51d

Please sign in to comment.