diff --git a/Common/Server/Types/Database/QueryHelper.ts b/Common/Server/Types/Database/QueryHelper.ts index ab0492010d3..2e70bd0e625 100644 --- a/Common/Server/Types/Database/QueryHelper.ts +++ b/Common/Server/Types/Database/QueryHelper.ts @@ -8,6 +8,13 @@ import { FindOperator, Raw } from "typeorm"; import { FindWhereProperty } from "../../../Types/BaseDatabase/Query"; export default class QueryHelper { + + public static sortByRandom(): FindWhereProperty { + return Raw(() => { + return "RANDOM()"; + }); + } + public static findWithSameText( text: string | number, ): FindWhereProperty { diff --git a/ProbeIngest/API/Monitor.ts b/ProbeIngest/API/Monitor.ts index 00d7ca08c4f..6f184d386e3 100644 --- a/ProbeIngest/API/Monitor.ts +++ b/ProbeIngest/API/Monitor.ts @@ -340,8 +340,8 @@ router.post( await MonitorProbeService.findBy({ query: getMonitorFetchQuery((req as OneUptimeRequest).probe!.id!), sort: { - nextPingAt: SortOrder.Ascending, - }, + nextPingAt: QueryHelper.sortByRandom(), // randomize the order of the monitors + } as any, skip: 0, limit: limit, select: {