Skip to content

Commit

Permalink
RE: add retrive selected bucket collections if selected collections a…
Browse files Browse the repository at this point in the history
…re not specifed
  • Loading branch information
serhii-filonenko committed Feb 7, 2024
1 parent 88d7dda commit 9f48506
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ const getDbCollectionsData = async (data, appLogger, callback, app) => {

try {
const connectionInfo = data.connectionInfo;
const collectionVersion = data.collectionData.collectionVersion;
const includeEmptyCollection = data.includeEmptyCollection;
const cluster = await connectionHelper.connect({ connectionInfo, app });
const indexes = await indexHelper.getIndexes({ cluster, connectionInfo, logger, app });
const selectedCollections = await clusterHelper.getSelectedCollections({ cluster, data, logger, app });
const indexesByCollectionMap = indexHelper.getIndexesByCollectionMap({ indexes });
const dbCollectionsData = [];

for (const bucketName in collectionVersion) {
for (const scopeName in collectionVersion[bucketName]) {
for (const collectionName of collectionVersion[bucketName][scopeName]) {
for (const bucketName in selectedCollections) {
for (const scopeName in selectedCollections[bucketName]) {
for (const collectionName of selectedCollections[bucketName][scopeName]) {
const collectionIndexes = indexesByCollectionMap[bucketName]?.[scopeName]?.[collectionName];
const dbCollectionData = await clusterHelper.getDbCollectionData({
cluster,
Expand Down
35 changes: 35 additions & 0 deletions reverse_engineering/helpers/clusterHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ const getDbCollectionData = async ({
}
};

/**
* @param {{ cluster: Cluster; logger: Logger }} param0
* @returns {Promise<object[]>}
*/
const getIndexes = async ({ cluster, logger }) => {
try {
const query = queryHelper.getSelectIndexesQuery();
Expand All @@ -488,6 +492,36 @@ const getIndexes = async ({ cluster, logger }) => {
}
};

/**
* @param { cluster: Cluster; data: object; logger: Logger; app: App } param0
* @returns {Promise<NameMap>}
*/
const getSelectedCollections = async ({ cluster, data, logger, app }) => {
const collectionVersion = data.collectionData.collectionVersion;
const dataBaseNames = data.collectionData.dataBaseNames;

if (!_.isEmpty(collectionVersion)) {
return collectionVersion;
}

const dbCollectionData = await async.flatMap(dataBaseNames, async bucketName => {
return getDbCollectionsNames({
connectionInfo: {
...data,
couchbase_bucket: bucketName,
},
cluster,
logger,
app,
});
});

return dbCollectionData.reduce((result, collectionData) => {
const { dbName, scopeName, dbCollections } = collectionData;
return _.set(result, [dbName, scopeName], dbCollections);
}, {});
};

module.exports = {
isBucketHasDefaultCollection,
getAllBuckets,
Expand All @@ -501,4 +535,5 @@ module.exports = {
getErrorMessage,
getIndexes,
getPaginatedQuery,
getSelectedCollections,
};

0 comments on commit 9f48506

Please sign in to comment.