Skip to content
Open
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: 1 addition & 20 deletions app/db/models/measurement.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { and, desc, eq, gt, gte, inArray, lt, lte, sql } from 'drizzle-orm'
import { ArchivedDeviceError } from './device.server'
import {
type LastMeasurement,
location,
Expand Down Expand Up @@ -235,25 +234,7 @@ export async function saveMeasurements(
})

await drizzleClient.transaction(async (tx) => {
const [currentDevice] = await tx
.select({
id: device.id,
archivedAt: device.archivedAt,
})
.from(device)
.where(eq(device.id, minimalDevice.id))
.limit(1)
timing?.mark('transactionDeviceLookup')

if (!currentDevice) {
const error = new Error('Device not found')
error.name = 'NotFoundError'
throw error
}

if (currentDevice.archivedAt) {
throw new ArchivedDeviceError(currentDevice.id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minimalDevice should carry the archivedAt field, you can keep the check but get rid of the redundant lookup.

}
timing?.mark('transactionStart')

const locations =
deviceLocationUpdates.length > 0
Expand Down
Loading