Server-side sorting for execution search results
Sorting now applies to the entire result set via ClickHouse ORDER BY instead of only sorting the current page client-side. Default sort order is timestamp descending. Supported sort columns: startTime, status, agentId, routeId, correlationId, durationMs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,8 @@ import java.time.Instant;
|
||||
* @param processorType matches processor_types array via has()
|
||||
* @param offset pagination offset (0-based)
|
||||
* @param limit page size (default 50, max 500)
|
||||
* @param sortField column to sort by (default: startTime)
|
||||
* @param sortDir sort direction: asc or desc (default: desc)
|
||||
*/
|
||||
public record SearchRequest(
|
||||
String status,
|
||||
@@ -39,15 +41,37 @@ public record SearchRequest(
|
||||
String agentId,
|
||||
String processorType,
|
||||
int offset,
|
||||
int limit
|
||||
int limit,
|
||||
String sortField,
|
||||
String sortDir
|
||||
) {
|
||||
|
||||
private static final int DEFAULT_LIMIT = 50;
|
||||
private static final int MAX_LIMIT = 500;
|
||||
|
||||
private static final java.util.Set<String> ALLOWED_SORT_FIELDS = java.util.Set.of(
|
||||
"startTime", "status", "agentId", "routeId", "correlationId", "durationMs"
|
||||
);
|
||||
|
||||
private static final java.util.Map<String, String> SORT_FIELD_TO_COLUMN = java.util.Map.of(
|
||||
"startTime", "start_time",
|
||||
"status", "status",
|
||||
"agentId", "agent_id",
|
||||
"routeId", "route_id",
|
||||
"correlationId", "correlation_id",
|
||||
"durationMs", "duration_ms"
|
||||
);
|
||||
|
||||
public SearchRequest {
|
||||
if (limit <= 0) limit = DEFAULT_LIMIT;
|
||||
if (limit > MAX_LIMIT) limit = MAX_LIMIT;
|
||||
if (offset < 0) offset = 0;
|
||||
if (sortField == null || !ALLOWED_SORT_FIELDS.contains(sortField)) sortField = "startTime";
|
||||
if (!"asc".equalsIgnoreCase(sortDir)) sortDir = "desc";
|
||||
}
|
||||
|
||||
/** Returns the validated ClickHouse column name for ORDER BY. */
|
||||
public String sortColumn() {
|
||||
return SORT_FIELD_TO_COLUMN.getOrDefault(sortField, "start_time");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user