Skip to content

Commit 16ad3aa

Browse files
committed
fix(history): limit number of returned items on history
Otherwise location history with tens of thousands locations will overwhelm the browser
1 parent 9acac99 commit 16ad3aa

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lambda/location-history/queryLocationHistory.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
DynamoDBClient,
3-
paginateQuery,
3+
QueryCommand,
44
type QueryCommandInput,
55
} from '@aws-sdk/client-dynamodb'
66
import { SSMClient } from '@aws-sdk/client-ssm'
@@ -14,7 +14,7 @@ import {
1414
validateInput,
1515
type ValidInput,
1616
} from '@hello.nrfcloud.com/lambda-helpers/validateInput'
17-
import { LwM2MObjectID, definitions } from '@hello.nrfcloud.com/proto-map/lwm2m'
17+
import { definitions, LwM2MObjectID } from '@hello.nrfcloud.com/proto-map/lwm2m'
1818
import { fingerprintRegExp } from '@hello.nrfcloud.com/proto/fingerprint'
1919
import {
2020
Context,
@@ -132,16 +132,13 @@ const h = async (
132132
},
133133
},
134134
ProjectionExpression: '#source, #lat, #lon, #uncertainty, #timestamp',
135+
Limit: 500,
136+
ScanIndexForward: false,
135137
}
136138
console.log('Query', JSON.stringify(Query))
137139

138-
const results = paginateQuery({ client: db }, Query)
139-
const items = []
140-
for await (const { Items } of results) {
141-
items.push(...(Items ?? []))
142-
}
143-
144-
console.log('Items', JSON.stringify(items))
140+
const { Items } = await db.send(new QueryCommand(Query))
141+
const items = Items ?? []
145142

146143
const history = (items.map((item) => unmarshall(item)) ?? []).map((item) => ({
147144
'0': item.lat as number,

lambda/memfault/queryReboots.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ const h = async (
109109
},
110110
},
111111
ProjectionExpression: '#reason, #timestamp',
112+
Limit: 250,
113+
ScanIndexForward: false,
112114
}
113115
console.log('Query', JSON.stringify(Query))
114116

0 commit comments

Comments
 (0)