mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 11:56:38 +00:00
perf(quota): Skip expensive usage checks when no quota configured (#1749)
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -36,6 +36,18 @@ impl QuotaChecker {
|
||||
bucket: &str,
|
||||
operation: QuotaOperation,
|
||||
operation_size: u64,
|
||||
) -> Result<QuotaCheckResult, QuotaError> {
|
||||
self.check_quota_with_usage_reporting(bucket, operation, operation_size, false)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Check quota with option to force usage calculation even when no quota is configured
|
||||
pub async fn check_quota_with_usage_reporting(
|
||||
&self,
|
||||
bucket: &str,
|
||||
operation: QuotaOperation,
|
||||
operation_size: u64,
|
||||
force_usage_calculation: bool,
|
||||
) -> Result<QuotaCheckResult, QuotaError> {
|
||||
let start_time = Instant::now();
|
||||
let quota_config = self.get_quota_config(bucket).await?;
|
||||
@@ -43,7 +55,11 @@ impl QuotaChecker {
|
||||
// If no quota limit is set, allow operation
|
||||
let quota_limit = match quota_config.quota {
|
||||
None => {
|
||||
let current_usage = self.get_real_time_usage(bucket).await?;
|
||||
let current_usage = if force_usage_calculation {
|
||||
Some(self.get_real_time_usage(bucket).await?)
|
||||
} else {
|
||||
None // Skip expensive usage calculation when no quota and not forced for performance
|
||||
};
|
||||
return Ok(QuotaCheckResult {
|
||||
allowed: true,
|
||||
current_usage,
|
||||
@@ -84,7 +100,7 @@ impl QuotaChecker {
|
||||
|
||||
let result = QuotaCheckResult {
|
||||
allowed,
|
||||
current_usage,
|
||||
current_usage: Some(current_usage),
|
||||
quota_limit: Some(quota_limit),
|
||||
operation_size,
|
||||
remaining,
|
||||
@@ -165,7 +181,7 @@ mod tests {
|
||||
async fn test_quota_check_no_limit() {
|
||||
let result = QuotaCheckResult {
|
||||
allowed: true,
|
||||
current_usage: 0,
|
||||
current_usage: None,
|
||||
quota_limit: None,
|
||||
operation_size: 1024,
|
||||
remaining: None,
|
||||
|
||||
@@ -80,7 +80,8 @@ impl BucketQuota {
|
||||
#[derive(Debug)]
|
||||
pub struct QuotaCheckResult {
|
||||
pub allowed: bool,
|
||||
pub current_usage: u64,
|
||||
/// current_usage: None when skipped for performance (no quota configured)
|
||||
pub current_usage: Option<u64>,
|
||||
/// quota_limit: None means unlimited
|
||||
pub quota_limit: Option<u64>,
|
||||
pub operation_size: u64,
|
||||
|
||||
Reference in New Issue
Block a user