fix: timing
This commit is contained in:
@@ -104,27 +104,31 @@ export class DevicesService {
|
|||||||
const tieBreaker = uuidv4().substring(0, 8);
|
const tieBreaker = uuidv4().substring(0, 8);
|
||||||
const cursor = Buffer.from(`${cursorTimestamp}:${tieBreaker}`).toString('base64url');
|
const cursor = Buffer.from(`${cursorTimestamp}:${tieBreaker}`).toString('base64url');
|
||||||
|
|
||||||
// Parse cursor from request if provided
|
// Build the Prisma where clause
|
||||||
let cursorCutoff = new Date(0);
|
const commandWhere: any = {
|
||||||
|
deviceId: device.id,
|
||||||
|
status: 'pending',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse cursor from request if provided — skip filter if cursor is missing or invalid
|
||||||
if (dto.cursor) {
|
if (dto.cursor) {
|
||||||
try {
|
try {
|
||||||
const decoded = Buffer.from(dto.cursor, 'base64url').toString('utf-8');
|
const decoded = Buffer.from(dto.cursor, 'base64url').toString('utf-8');
|
||||||
const parts = decoded.split(':');
|
const parts = decoded.split(':');
|
||||||
if (parts.length >= 1) {
|
if (parts.length >= 1) {
|
||||||
cursorCutoff = new Date(parts[0]);
|
const parsed = new Date(parts[0]);
|
||||||
|
if (!isNaN(parsed.getTime())) {
|
||||||
|
commandWhere.createdAt = { gt: parsed };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Invalid cursor, return all pending commands
|
// Invalid cursor — ignore filter, return all pending commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find pending commands for this device
|
// Find pending commands for this device
|
||||||
const commands = await this.prisma.remoteCommand.findMany({
|
const commands = await this.prisma.remoteCommand.findMany({
|
||||||
where: {
|
where: commandWhere,
|
||||||
deviceId: device.id,
|
|
||||||
status: 'pending',
|
|
||||||
createdAt: { gt: cursorCutoff },
|
|
||||||
},
|
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
type: true,
|
type: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user