From 90dcd0d90e40edf2a4f28da85ba84e500e519475 Mon Sep 17 00:00:00 2001 From: Hengfei Yang Date: Fri, 15 Dec 2023 18:29:53 +0800 Subject: [PATCH] fix: #2201 (#2207) --- src/service/db/alerts/destinations.rs | 8 +++++--- src/service/db/alerts/templates.rs | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/service/db/alerts/destinations.rs b/src/service/db/alerts/destinations.rs index 7f86a8f360..d3a6caf579 100644 --- a/src/service/db/alerts/destinations.rs +++ b/src/service/db/alerts/destinations.rs @@ -15,6 +15,8 @@ use std::sync::Arc; +use itertools::Itertools; + use crate::common::{ infra::{config::ALERTS_DESTINATIONS, db as infra_db}, meta::alerts::destinations::Destination, @@ -55,14 +57,14 @@ pub async fn delete(org_id: &str, name: &str) -> Result<(), anyhow::Error> { pub async fn list(org_id: &str) -> Result, anyhow::Error> { let cache = ALERTS_DESTINATIONS.clone(); if !cache.is_empty() { - let items: Vec = cache + return Ok(cache .iter() .filter_map(|dest| { let k = dest.key(); (k.starts_with(&format!("{org_id}/"))).then(|| dest.value().clone()) }) - .collect(); - return Ok(items); + .sorted_by(|a, b| a.name.cmp(&b.name)) + .collect()); } let db = infra_db::get_db().await; diff --git a/src/service/db/alerts/templates.rs b/src/service/db/alerts/templates.rs index 9ecd8531a8..927a1a10a2 100644 --- a/src/service/db/alerts/templates.rs +++ b/src/service/db/alerts/templates.rs @@ -15,6 +15,8 @@ use std::sync::Arc; +use itertools::Itertools; + use crate::common::{ infra::{config::ALERTS_TEMPLATES, db as infra_db}, meta::{alerts::templates::Template, organization::DEFAULT_ORG}, @@ -70,6 +72,7 @@ pub async fn list(org_id: &str) -> Result, anyhow::Error> { (k.starts_with(&format!("{org_id}/")) || k.starts_with(&format!("{DEFAULT_ORG}/"))) .then(|| template.value().clone()) }) + .sorted_by(|a, b| a.name.cmp(&b.name)) .collect()); }