Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download rate limit #404

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Download rate limit #404

wants to merge 7 commits into from

Conversation

awu0403
Copy link
Contributor

@awu0403 awu0403 commented Oct 25, 2024

No description provided.

# Update UserTraffic
for row in local_traffic_info[date_str]:
trans_count += 1
org_id = row[0]
user = row[1]
oper = row[2]
size = local_traffic_info[date_str][row]
if oper in self.download_type_list:
traffic_threshold = traffic_info_dict[user]['monthly_rate_limit'] if traffic_info_dict else 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image try 里面的内容放到这个if 里,except 中的放到else 中 是不是代码更清晰?


try:
# Check the download traffic for the current month.
if (not (org_id > 0) and oper in self.download_type_list and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not (org_id > 0) 换成org_id<0吧

return traffic_info_list


def reset_download_rate_limit():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样重置限速是不是不合理?因为限速信息是在内存里,服务器重启的话,这些用户的限速就解除不了了吧

try:
seahub_api = SeahubAPI()
download_traffic_info = format_download_traffic_info(local_traffic_info, date_str, self.download_type_list)
traffic_info_dict = seahub_api.get_download_rate_limit_info(download_traffic_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把所有有下载记录的用户都传过去,来获取每个人的限速信息,是不是得调整一下?改成只获取角色的限速信息,具体这个用户限速多少,在seafevents 中进行处理是不是更合适

org = ccnet_api.get_org_by_id(org_id)
org_users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
org_user_list[org_id] = org_users
return org_user_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名需要改一下,返回的并不是列表类型,接收这个函数返回值的变量名也要修改,查询是不是不用ccnet_api了?改成直接查数据库吧,查询角色的也需要改一下

UserTraffic.org_id == org_id,
UserTraffic.op_type.in_(self.download_type_list)
)
monthly_result = self.edb_session.scalars(stmt2).first()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名改成user_monthly_traffic_size

try:
# Check org download traffic for current month.
if (org_id > 0 and oper in self.download_type_list and
(org_id not in rate_limit_orgs or not rate_limit_orgs[org_id])):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是可以用 rate_limit_orgs.get(org) 这种形式替换一下?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants