Skip to content

Commit

Permalink
fix: invert flows of gathering indexes (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
chulanovskyi-bs authored Dec 26, 2024
1 parent e07684b commit 2d89257
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions reverse_engineering/helpers/indexHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,37 @@ const getWhereCondition = index => {

const getIndexes = async ({ cluster, connectionInfo, logger }) => {
try {
const indexData = await restApiHelper.getIndexes({ connectionInfo, logger });
const statements = indexData.map(indx => indx.definition).join(';\n');

if (!statements) {
return [];
}

const { indexes } = parserHelper.parseN1qlStatements({ statements });

return indexes;
const indexes = await clusterHelper.getIndexes({ cluster, logger });

return indexes
.toSorted((a, b) => a.name.localeCompare(b.name))
.map(index => {
const isDefaultCollectionIndex = !index.bucket_id;
const bucketName = isDefaultCollectionIndex ? index.keyspace_id : index.bucket_id;
const scopeName = isDefaultCollectionIndex ? DEFAULT_NAME : index.scope_id;
const collectionName = isDefaultCollectionIndex ? DEFAULT_NAME : index.keyspace_id;

return {
index: handleIndex(index),
bucketName,
scopeName,
collectionName,
};
});
} catch (error) {
try {
logger.error(error);

const indexes = await clusterHelper.getIndexes({ cluster, logger });

return indexes
.toSorted((a, b) => a.name.localeCompare(b.name))
.map(index => {
const isDefaultCollectionIndex = !index.bucket_id;
const bucketName = isDefaultCollectionIndex ? index.keyspace_id : index.bucket_id;
const scopeName = isDefaultCollectionIndex ? DEFAULT_NAME : index.scope_id;
const collectionName = isDefaultCollectionIndex ? DEFAULT_NAME : index.keyspace_id;

return {
index: handleIndex(index),
bucketName,
scopeName,
collectionName,
};
});
const indexData = await restApiHelper.getIndexes({ connectionInfo, logger });
const statements = indexData.map(indx => indx.definition).join(';\n');

if (!statements) {
return [];
}

const { indexes } = parserHelper.parseN1qlStatements({ statements });

return indexes;
} catch (err) {
logger.error(err);
return [];
Expand Down

0 comments on commit 2d89257

Please sign in to comment.