perf: 使用列表推导式替换循环 - 优化group_by性能
This commit is contained in:
@@ -458,10 +458,11 @@ class AggregateQuery:
|
||||
if not fields:
|
||||
raise ValueError("至少需要一个分组字段")
|
||||
|
||||
group_columns = []
|
||||
for field_name in fields:
|
||||
if hasattr(self.model, field_name):
|
||||
group_columns.append(getattr(self.model, field_name))
|
||||
group_columns = [
|
||||
getattr(self.model, field_name)
|
||||
for field_name in fields
|
||||
if hasattr(self.model, field_name)
|
||||
]
|
||||
|
||||
if not group_columns:
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user