Skip to content

Commit

Permalink
Issue #SB-17538 merge: Merge pull request #267 from swayangjit/releas…
Browse files Browse the repository at this point in the history
…e-2.7.0

Issue #SB-17538 fix: Added sort logic while getting the child ids from DB.
  • Loading branch information
AmiableAnil authored Jan 21, 2020
2 parents 3900cb4 + 8de9d96 commit fb0bd41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunbird-sdk",
"version": "2.7.12",
"version": "2.7.13",
"description": "Heart of the sunbird mobile app.",
"main": "dist/index.js",
"scripts": {
Expand Down
33 changes: 12 additions & 21 deletions src/content/handlers/import-n-export-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,10 @@ export class ImportNExportHandler {
childContents.forEach(element => {
childIdentifiers.push(element.identifier);
});
contentModelToExport = await this.findAllContentsWithIdentifiers(childIdentifiers);
contentModelToExport = await this.findAllContentsWithIdentifiers(childIdentifiers, true);
}).catch((err) => {
console.log('fileRead error', err);
});
// contentsInDb.forEach((contentInDb) => {
// queue.add(contentInDb);
// });
// let node: ContentEntry.SchemaMap;
// while (!queue.isEmpty()) {
// node = queue.dequeue()!;
// if (ContentUtil.hasChildren(node[ContentEntry.COLUMN_NAME_LOCAL_DATA])) {
// const childContentsIdentifiers: string[] = ContentUtil.getChildContentsIdentifiers(node[COLUMN_NAME_LOCAL_DATA]);
// const contentModelListInDB: ContentEntry.SchemaMap[] = await this.findAllContentsWithIdentifiers(
// childContentsIdentifiers);
// if (contentModelListInDB && contentModelListInDB.length > 0) {
// contentModelListInDB.forEach((contentModelInDb) => {
// queue.add(contentModelInDb);
// });
// }
// }
// contentModelToExport.push(node);
// }
return Promise.resolve(ContentUtil.deDupe(contentModelToExport, 'identifier'));
}

Expand All @@ -141,10 +123,19 @@ export class ImportNExportHandler {
return manifest;
}

private findAllContentsWithIdentifiers(identifiers: string[]): Promise<ContentEntry.SchemaMap[]> {
private findAllContentsWithIdentifiers(identifiers: string[], sort?): Promise<ContentEntry.SchemaMap[]> {
let orderByString = '';
if (sort) {
if (identifiers.length) {
orderByString = identifiers.reduce((acc, identifier, index) => {
return acc + ` WHEN '${identifier}' THEN ${index}`;
}, ` ORDER BY CASE ${COLUMN_NAME_IDENTIFIER}`) + ' END';
}
}

const identifiersStr = ArrayUtil.joinPreservingQuotes(identifiers);
const filter = ` where ${COLUMN_NAME_IDENTIFIER} in (${identifiersStr}) AND ${COLUMN_NAME_REF_COUNT} > 0`;
const query = `select * from ${ContentEntry.TABLE_NAME} ${filter}`;
const query = `select * from ${ContentEntry.TABLE_NAME} ${filter} ${orderByString}`;
return this.dbService!.execute(query).toPromise();
}
}

0 comments on commit fb0bd41

Please sign in to comment.