Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/modules/asset/AssetsGroupsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,17 @@ export class AssetsGroupsController {
async checkGroupName(
engineId: string,
name: AssetsGroupsBodyRequest["name"],
assetId?: string,
groupId?: string,
) {
if (typeof name !== "string") {
return;
}

const groupsCount = await this.sdk.document.count(
const groupsCount = await this.sdk.document.search(
engineId,
InternalCollection.ASSETS_GROUPS,
{
_source: false,
query: {
bool: {
must: [
Expand All @@ -198,19 +199,15 @@ export class AssetsGroupsController {
},
},
],
must_not: [
{
terms: {
_id: typeof assetId === "string" ? [assetId] : [],
},
},
],
},
},
},
);

if (groupsCount > 0) {
if (groupsCount.total > 0) {
if (groupsCount.total === 1 && groupsCount.hits[0]._id === groupId) {
return;
Comment on lines +208 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throwing an error if a group with the same name exists?

}
throw new BadRequestError(`A group with name "${name}" already exist`);
}
}
Expand Down Expand Up @@ -279,7 +276,9 @@ export class AssetsGroupsController {
if (model !== null) {
const groupModel = await ask<AskModelGroupGet>(
"ask:device-manager:model:group:get",
{ model },
{
model,
},
);
for (const metadataName of Object.keys(
groupModel.group.metadataMappings,
Expand Down
13 changes: 1 addition & 12 deletions lib/modules/measure/MeasureExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ export class MeasureExporter extends AbstractExporter<MeasureExportParams> {
query: searchQuery,
sort: params.sort ?? { measuredAt: "desc" },
};

/**
* ? Prevent error duplicate result on search with sort.
* "Unable to retrieve all results from search: the sort combination must identify one item only. Add document "_id" to the sort."
*/
if (exportParams.sort._id === undefined) {
exportParams.sort._id = "asc";
}

return super.prepareExport(engineId, user, exportParams);
}

Expand Down Expand Up @@ -154,14 +145,12 @@ export class MeasureExporter extends AbstractExporter<MeasureExportParams> {
model,
lang = "elasticsearch",
} = await this.getExport(engineId, exportId);

const result = await this.sdk.document.search<MeasureContent>(
engineId,
InternalCollection.MEASURES,
{ query, sort },
{ lang, size: 200 },
{ lang, scroll: "20s", size: 200 },
);

const targetModel =
this.target === InternalCollection.ASSETS ? "asset" : "device";
const engine = await this.getEngine(engineId);
Expand Down
3 changes: 1 addition & 2 deletions lib/modules/shared/services/AbstractExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export abstract class AbstractExporter<P extends ExportParams = ExportParams> {
for (const hit of result.hits) {
stream.write(stringify([this.formatHit(columns, hit)]));
}

result = result.fetched < 10000 ? await result.next() : null;
result = await result.next();
}
} catch (error) {
stream.write(error.message);
Expand Down