Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mget instead of single get on getStates for alias ids #2077

Merged
merged 1 commit into from
Dec 30, 2022
Merged
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
22 changes: 9 additions & 13 deletions packages/adapter/src/lib/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,22 +1304,18 @@ export class AdapterClass extends EventEmitter {
keys: string[],
objects: ioBroker.AnyObject[] | null,
options?: Record<string, any> | null
): Promise<(ioBroker.AnyObject | null | undefined)[]> {
): Promise<(ioBroker.AnyObject | null)[]> {
if (objects) {
return objects;
}

const res: (ioBroker.AnyObject | null | undefined)[] = [];
for (const key of keys) {
try {
const obj = await this.getForeignObjectAsync(key, options);
res.push(obj);
} catch {
res.push(null);
}
try {
const res = await adapterObjects!.getObjects(keys, options);
return res;
} catch (e) {
this._logger.error(`Could not get objects by array: ${e.message}`);
return [];
}

return res;
}

// external signature
Expand Down Expand Up @@ -9043,7 +9039,7 @@ export class AdapterClass extends EventEmitter {
result[obj._id || keys[i]] = arr![i] || null;
}
} else {
result[(obj && obj._id) || keys[i]] = arr![i] || null;
result[obj?._id || keys[i]] = arr![i] || null;
}
}
// @ts-expect-error https://github.com/ioBroker/adapter-core/issues/455
Expand Down Expand Up @@ -9077,7 +9073,7 @@ export class AdapterClass extends EventEmitter {
const srcIds: string[] = [];
// replace aliases ID with targets
targetObjs.forEach((obj, i) => {
if (obj && obj.common && obj.common.alias) {
if (obj?.common?.alias) {
// alias id can be string or can have attribute read (this is used by getStates -> so read is important)
const aliasId =
// @ts-expect-error
Expand Down