Skip to content

Commit

Permalink
Add random sorting method to QueryHelper and apply it in Monitor prob…
Browse files Browse the repository at this point in the history
…e fetching
  • Loading branch information
simlarsen committed Nov 26, 2024
1 parent 93027ec commit b10134f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Common/Server/Types/Database/QueryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { FindOperator, Raw } from "typeorm";
import { FindWhereProperty } from "../../../Types/BaseDatabase/Query";

export default class QueryHelper {

public static sortByRandom(): FindWhereProperty<any> {
return Raw(() => {
return "RANDOM()";
});
}

public static findWithSameText(
text: string | number,
): FindWhereProperty<any> {
Expand Down
4 changes: 2 additions & 2 deletions ProbeIngest/API/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit b10134f

Please sign in to comment.