Change import pagination / type schema validation
MODIFY
src/scheduler/tasks/SynchronizeTagsImportTask.ts
src/scheduler/tasks/SynchronizeTagsImportTask.ts
@@ -10,6 +10,7 @@ import Tag from '../../types/Tag';
import TagStorage from '../../storage/mongodb/TagStorage';
import { TaskConfig } from '../../types/TaskConfig';
import Tenant from '../../types/Tenant';
+import Utils from '../../utils/Utils';
const MODULE_NAME = 'SynchronizeUsersImportTask';
@@ -18,16 +19,9 @@ export default class SynchronizeTagsImportTask extends SchedulerTask {
const synchronizeTagsImport = LockingManager.createExclusiveLock(tenant.id, LockEntity.TAGS, 'synchronize-tags-import');
if (await LockingManager.acquire(synchronizeTagsImport)) {
try {
- const dbParams: DbParams = { limit: Constants.EXPORT_PAGE_SIZE, skip: 0, onlyRecordCount: true };
+ const dbParams: DbParams = { limit: Constants.EXPORT_PAGE_SIZE, skip: 0 };
let importedTags = await TagStorage.getImportedTags(tenant.id, { withNoError: true }, dbParams);
- let count = importedTags.count;
- delete dbParams.onlyRecordCount;
- let skip = 0;
- // Limit the number of records
- if (count > Constants.EXPORT_RECORD_MAX_COUNT) {
- count = Constants.EXPORT_RECORD_MAX_COUNT;
- }
- do {
+ while (importedTags && !Utils.isEmptyArray(importedTags.result)) {
importedTags = await TagStorage.getImportedTags(tenant.id, { withNoError: true }, dbParams);
for (const importedTag of importedTags.result) {
const foundTag = await TagStorage.getTag(tenant.id, importedTag.id);
@@ -69,8 +63,8 @@ export default class SynchronizeTagsImportTask extends SchedulerTask {
}
}
}
- skip += Constants.EXPORT_PAGE_SIZE;
- } while (skip < count);
+ importedTags = await TagStorage.getImportedTags(tenant.id, { withNoError: true }, dbParams);
+ }
} catch (error) {
// Log error
await Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_TAGS, error);

MODIFY
src/scheduler/tasks/SynchronizeUsersImportTask.ts
src/scheduler/tasks/SynchronizeUsersImportTask.ts
@@ -11,6 +11,7 @@ import { ServerAction } from '../../types/Server';
import { TaskConfig } from '../../types/TaskConfig';
import Tenant from '../../types/Tenant';
import UserStorage from '../../storage/mongodb/UserStorage';
+import Utils from '../../utils/Utils';
const MODULE_NAME = 'SynchronizeUsersImportTask';
@@ -19,17 +20,9 @@ export default class SynchronizeUsersImportTask extends SchedulerTask {
const synchronizeUsersImport = LockingManager.createExclusiveLock(tenant.id, LockEntity.USER, 'synchronize-users-import');
if (await LockingManager.acquire(synchronizeUsersImport)) {
try {
- const dbParams: DbParams = { limit: Constants.EXPORT_PAGE_SIZE, skip: 0, onlyRecordCount: true };
+ const dbParams: DbParams = { limit: Constants.EXPORT_PAGE_SIZE, skip: 0 };
let importedUsers = await UserStorage.getImportedUsers(tenant.id, { withNoError: true }, dbParams);
- let count = importedUsers.count;
- delete dbParams.onlyRecordCount;
- let skip = 0;
- // Limit the number of records
- if (count > Constants.EXPORT_RECORD_MAX_COUNT) {
- count = Constants.EXPORT_RECORD_MAX_COUNT;
- }
- do {
- importedUsers = await UserStorage.getImportedUsers(tenant.id, { withNoError: true }, dbParams);
+ while (importedUsers && !Utils.isEmptyArray(importedUsers.result)) {
for (const importedUser of importedUsers.result) {
const foundUser = await UserStorage.getUserByEmail(tenant.id, importedUser.email);
if (foundUser) {
@@ -78,8 +71,8 @@ export default class SynchronizeUsersImportTask extends SchedulerTask {
}
}
}
- skip += Constants.EXPORT_PAGE_SIZE;
- } while (skip < count);
+ importedUsers = await UserStorage.getImportedUsers(tenant.id, { withNoError: true }, dbParams);
+ }
} catch (error) {
// Log error
await Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_USERS, error);

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -499,8 +499,8 @@ export default class TagService {
void file.pipe(converter);
} else if (mimetype === 'application/json') {
const parser = JSONStream.parse('tags.*');
- parser.on('data', async (tag) => {
- await TagService.importTag(action, req, tag);
+ parser.on('data', (tag) => {
+ void TagService.importTag(action, req, tag);
});
parser.on('error', function(error) {
void Logging.logError({

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -886,8 +886,8 @@ export default class UserService {
void file.pipe(converter);
} else if (mimetype === 'application/json') {
const parser = JSONStream.parse('users.*');
- parser.on('data', async (user) => {
- await UserService.importUser(action, req, user);
+ parser.on('data', (user) => {
+ void UserService.importUser(action, req, user);
});
parser.on('error', function(error) {
void Logging.logError({

MODIFY
src/server/rest/v1/validator/TagValidation.ts
src/server/rest/v1/validator/TagValidation.ts
+import { ImportedTag } from '../../../../types/Tag';
+import Schema from './Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
import global from '../../../../types/GlobalType';
export default class TagValidator extends SchemaValidator {
private static instance: TagValidator|null = null;
- private tagCreation: any;
+ private tagCreation: Schema;
private constructor() {
super('TagValidator');
@@ -18,7 +20,7 @@ export default class TagValidator extends SchemaValidator {
return TagValidator.instance;
}
- validateTagCreation(content): void {
- this.validate(this.tagCreation, content);
+ validateTagCreation(importedTag: ImportedTag): void {
+ this.validate(this.tagCreation, importedTag);
}
}

MODIFY
src/server/rest/v1/validator/UserValidation.ts
src/server/rest/v1/validator/UserValidation.ts
+import { ImportedUser } from '../../../../types/User';
+import Schema from './Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
import global from '../../../../types/GlobalType';
export default class UserValidator extends SchemaValidator {
private static instance: UserValidator|null = null;
- private userCreation: any;
+ private userCreation: Schema;
private constructor() {
super('UserValidator');
@@ -18,7 +20,7 @@ export default class UserValidator extends SchemaValidator {
return UserValidator.instance;
}
- validateUserCreation(content): void {
- this.validate(this.userCreation, content);
+ validateUserCreation(importedUser: ImportedUser): void {
+ this.validate(this.userCreation, importedUser);
}
}

Change import pagination / type schema validation