Skip to content

Commit

Permalink
Merge pull request #368 from balena-io/optimize-request
Browse files Browse the repository at this point in the history
Optimize the API request to fetch only the uuid & of only the accessible devices
  • Loading branch information
flowzone-app[bot] authored Sep 16, 2024
2 parents a6034ec + 6179b70 commit ab59ffa
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface PublishedHosts {
/** List of published hosts */
const publishedHosts: PublishedHosts[] = [];
/** List of devices with accessible public URLs */
let accessibleDevices: BalenaSdk.Device[] = [];
let accessibleDevices: Array<Pick<BalenaSdk.Device, 'uuid'>> = [];

/** DBus controller */
const dbus = systemBus();
Expand Down Expand Up @@ -143,22 +143,22 @@ const reapDevices = async (addresses: string[], deviceTld?: string) => {
for (const address of addresses) {
// Query the SDK using the Proxy service key for *all* current devices
try {
const devices = await balena.pine.get({
resource: 'device',
options: {$orderby: 'device_name asc'}
}) as BalenaSdk.Device[];

// Get list of all accessible devices
const newAccessible = _.filter(
devices,
(device) => device.is_web_accessible,
);
const newAccessible = await balena.pine.get({
resource: 'device',
options: {
$select: 'uuid',
$filter: {
is_web_accessible: true,
},
},
});

// Get all devices that are not in both lists
const xorList = _.xorBy(accessibleDevices, newAccessible, 'uuid');

// Get all new devices to be published and old to be unpublished
const toUnpublish: BalenaSdk.Device[] = [];
const toUnpublish: typeof newAccessible = [];
const toPublish = _.filter(xorList, (device) => {
const filter = _.find(newAccessible, { uuid: device.uuid })
? true
Expand Down

0 comments on commit ab59ffa

Please sign in to comment.