From 31de82bcd376be63337c2d563d48a07f9ed9ca1a Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Sat, 27 May 2023 14:31:13 +0900 Subject: [PATCH] refactor: move code out of loop (#1657) --- src/meta-srv/src/handler.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/meta-srv/src/handler.rs b/src/meta-srv/src/handler.rs index 62efd0692f2c..ee55d51c716d 100644 --- a/src/meta-srv/src/handler.rs +++ b/src/meta-srv/src/handler.rs @@ -183,19 +183,19 @@ impl HeartbeatHandlerGroup { ) -> Result { let mut acc = HeartbeatAccumulator::default(); let handlers = self.handlers.read().await; + let role = req + .header + .as_ref() + .and_then(|h| Role::from_i32(h.role)) + .context(error::InvalidArgumentsSnafu { + err_msg: format!("invalid role: {:?}", req.header), + })?; + for h in handlers.iter() { if ctx.is_skip_all() { break; } - let role = req - .header - .as_ref() - .and_then(|h| Role::from_i32(h.role)) - .context(error::InvalidArgumentsSnafu { - err_msg: format!("invalid role: {:?}", req.header), - })?; - if h.is_acceptable(role) { h.handle(&req, &mut ctx, &mut acc).await?; }