xf
This commit is contained in:
24
app/utils.py
24
app/utils.py
@@ -312,21 +312,29 @@ def get_all_emails(count=50):
|
||||
:return: 邮件列表
|
||||
"""
|
||||
try:
|
||||
# 1. 获取所有时间索引键,因为时间索引包含了所有邮件
|
||||
# 1. 获取所有时间索引键
|
||||
time_keys = redis_client.keys('time:*')
|
||||
time_keys.sort(reverse=True) # 按时间倒序排序
|
||||
time_keys = time_keys[:count] # 限制数量
|
||||
logger.debug(f"Found {len(time_keys)} time keys")
|
||||
|
||||
time_keys.sort(reverse=True)
|
||||
time_keys = time_keys[:count]
|
||||
logger.debug(f"Using {len(time_keys)} most recent time keys")
|
||||
|
||||
emails = []
|
||||
for time_key in time_keys:
|
||||
# 2. 从时间索引获取邮件键
|
||||
logger.debug(f"Processing time key: {time_key}")
|
||||
email_key = redis_client.get(time_key)
|
||||
if not email_key:
|
||||
logger.warning(f"No email key found for time key: {time_key}")
|
||||
continue
|
||||
|
||||
logger.debug(f"Found email key: {email_key}")
|
||||
|
||||
# 3. 获取邮件数据
|
||||
email_data = redis_client.hgetall(email_key)
|
||||
if email_data:
|
||||
logger.debug(f"Found email data with {len(email_data)} fields")
|
||||
# 4. 转换字节数据为字符串
|
||||
email = {k.decode(): v.decode() for k, v in email_data.items()}
|
||||
# 5. 解析 JSON 字符串字段
|
||||
@@ -334,12 +342,16 @@ def get_all_emails(count=50):
|
||||
if field in email:
|
||||
try:
|
||||
email[field] = json.loads(email[field])
|
||||
except:
|
||||
pass
|
||||
logger.debug(f"Successfully parsed {field} field")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to parse {field} field: {str(e)}")
|
||||
emails.append(email)
|
||||
else:
|
||||
logger.warning(f"No email data found for key: {email_key}")
|
||||
|
||||
logger.info(f"Successfully retrieved {len(emails)} emails")
|
||||
return emails
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting all emails: {str(e)}")
|
||||
logger.error(f"Error getting all emails: {str(e)}", exc_info=True)
|
||||
return []
|
||||
Reference in New Issue
Block a user