Skip to content

Commit ea9f2fb

Browse files
committed
refactor(cli): Review fixing
1 parent 1f562c5 commit ea9f2fb

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

templates/cli/lib/commands/push.js.twig

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const awaitPools = {
152152
if (steps > 1 && iteration === 1) {
153153
pollMaxDebounces *= steps;
154154

155-
log('Found a large number of deleting attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
155+
log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
156156
}
157157

158158
const { attributes } = await paginate(databasesListAttributes, {
@@ -727,18 +727,17 @@ const mapChangeAttribute = (attribute, collection, isAdding) => {
727727
};
728728

729729
const updatedList = async (remoteAttributes, localAttributes, collection) => {
730+
730731
const deleting = remoteAttributes.filter((attribute) => !findMatch(attribute, localAttributes)).map((attr) => mapChangeAttribute(attr, collection, false));
731732
const adding = localAttributes.filter((attribute) => !findMatch(attribute, remoteAttributes)).map((attr) => mapChangeAttribute(attr, collection, true));
732733
const conflicts = remoteAttributes.map((attribute) => deepSimilar(attribute, findMatch(attribute, localAttributes), collection)).filter(attribute => attribute !== undefined);
733-
let changedAttributes = [];
734734

735+
let changedAttributes = [];
735736
const changing = [...deleting, ...adding, ...conflicts]
736-
737737
if (changing.length === 0) {
738738
return changedAttributes;
739739
}
740740
log('There are pending changes in your collection deployment');
741-
742741
drawTable(changing.map((change) => {
743742
return { Key: change.key, Action: change.action, Reason: change.reason, };
744743
}));
@@ -751,16 +750,12 @@ const updatedList = async (remoteAttributes, localAttributes, collection) => {
751750

752751
if (conflicts.length > 0) {
753752
changedAttributes = conflicts.map((change) => change.attribute);
754-
755753
await Promise.all(changedAttributes.map((changed) => deleteAttribute(collection, changed)));
756-
757754
remoteAttributes = remoteAttributes.filter((attribute) => !findMatch(attribute, changedAttributes))
758755
}
759756

760757
const deletingAttributes = deleting.map((change) => change.attribute);
761-
762758
await Promise.all(deletingAttributes.map((attribute) => deleteAttribute(collection, attribute)));
763-
764759
const attributeKeys = [...remoteAttributes.map(attribute => attribute.key), ...deletingAttributes.map(attribute => attribute.key)]
765760

766761
if (attributeKeys.length) {
@@ -793,33 +788,33 @@ const pushCollection = async ({ all, yes } = {}) => {
793788
collections.push(collection);
794789
})
795790
}
796-
const databases = Array.from(new Set(collections.map(c => c['databaseId'])));
791+
const databases = Array.from(new Set(collections.map(collection => collection['databaseId'])));
797792

798793
// Parallel db actions
799-
await Promise.all(databases.map(async (dbId) => {
800-
const localDatabase = localConfig.getDatabase(dbId);
794+
await Promise.all(databases.map(async (databaseId) => {
795+
const localDatabase = localConfig.getDatabase(databaseId);
801796

802797
try {
803798
const database = await databasesGet({
804-
databaseId: dbId,
799+
databaseId: databaseId,
805800
parseOutput: false,
806801
});
807802

808-
if (database.name !== (localDatabase.name ?? dbId)) {
803+
if (database.name !== (localDatabase.name ?? databaseId)) {
809804
await databasesUpdate({
810-
databaseId: dbId,
811-
name: localDatabase.name ?? dbId,
805+
databaseId: databaseId,
806+
name: localDatabase.name ?? databaseId,
812807
parseOutput: false
813808
})
814809

815-
success(`Updated ${localDatabase.name} ( ${dbId} ) name`);
810+
success(`Updated ${localDatabase.name} ( ${databaseId} ) name`);
816811
}
817812
} catch (err) {
818-
log(`Database ${dbId} not found. Creating it now...`);
813+
log(`Database ${databaseId} not found. Creating it now...`);
819814

820815
await databasesCreate({
821-
databaseId: dbId,
822-
name: localDatabase.name ?? dbId,
816+
databaseId: databaseId,
817+
name: localDatabase.name ?? databaseId,
823818
parseOutput: false,
824819
});
825820
}
@@ -858,7 +853,6 @@ const pushCollection = async ({ all, yes } = {}) => {
858853
permissions: collection['$permissions'],
859854
parseOutput: false
860855
})
861-
collection.isNew = true;
862856
} else {
863857
throw e;
864858
}
@@ -914,7 +908,7 @@ const createIndexes = async (indexes, collection) => {
914908
const result = await awaitPools.expectIndexes(
915909
collection['databaseId'],
916910
collection['$id'],
917-
indexes.map(attribute => attribute.key)
911+
indexes.map(index => index.key)
918912
);
919913

920914
if (!result) {

0 commit comments

Comments
 (0)