seawolf2357 commited on
Commit
1b1be7b
·
verified ·
1 Parent(s): ffa8090

Update cache_db.py

Browse files
Files changed (1) hide show
  1. cache_db.py +38 -12
cache_db.py CHANGED
@@ -576,7 +576,7 @@ class ContentVectorCache:
576
  "failed_count": len(self._index_status["failed"])
577
  }
578
  class UserProfileCache:
579
- """사용자 프로필 저장/로드 클래스 (이메일 기반)"""
580
  def __init__(self):
581
  self.profiles_file = PROFILE_DIR / "profiles.json"
582
  self.profiles = {}
@@ -601,30 +601,54 @@ class UserProfileCache:
601
  def _normalize_email(self, email: str) -> str:
602
  """이메일 정규화 (소문자 변환, 공백 제거)"""
603
  return email.strip().lower()
604
- def save_profile(self, email: str, profile_data: dict) -> Tuple[bool, str]:
605
- """프로필 저장"""
606
  if not email or '@' not in email:
607
  return False, "올바른 이메일 주소를 입력해주세요."
608
  email_key = self._normalize_email(email)
 
 
 
 
 
 
609
  self.profiles[email_key] = {
610
  "email": email_key,
611
  "profile": profile_data,
 
612
  "updated_at": datetime.now(KST).isoformat(),
613
  "created_at": self.profiles.get(email_key, {}).get("created_at", datetime.now(KST).isoformat())
614
  }
615
  self._save_profiles()
616
- logger.info(f"Profile saved for: {email_key}")
617
- return True, f" 프로필이 저장되었습니다. ({email_key})"
618
- def load_profile(self, email: str) -> Tuple[Optional[dict], str]:
619
- """프로필 로드"""
 
620
  if not email or '@' not in email:
621
- return None, "올바른 이메일 주소를 입력해주세요."
622
  email_key = self._normalize_email(email)
623
  if email_key in self.profiles:
624
  data = self.profiles[email_key]
 
 
 
 
 
625
  logger.info(f"Profile loaded for: {email_key}")
626
- return data.get("profile", {}), f"✅ 프로필을 불러왔습니다. (마지막 수정: {data.get('updated_at', '알 수 없음')[:10]})"
627
- return None, f"ℹ️ '{email_key}'에 저장된 프로필이 없습니다. 새로 입력해주세요."
 
 
 
 
 
 
 
 
 
 
 
628
  def delete_profile(self, email: str) -> Tuple[bool, str]:
629
  """프로필 삭제"""
630
  email_key = self._normalize_email(email)
@@ -636,6 +660,9 @@ class UserProfileCache:
636
  def get_profile_count(self) -> int:
637
  """저장된 프로필 수"""
638
  return len(self.profiles)
 
 
 
639
  _cache_instance = None
640
  _content_cache_instance = None
641
  _profile_cache_instance = None
@@ -934,5 +961,4 @@ def initialize_cache_system():
934
  if __name__ == "__main__":
935
  print("Testing cache system...")
936
  status = initialize_cache_system()
937
- print(f"Status: {json.dumps(status, ensure_ascii=False, indent=2)}")
938
-
 
576
  "failed_count": len(self._index_status["failed"])
577
  }
578
  class UserProfileCache:
579
+ """사용자 프로필 저장/로드 클래스 (이메일 기반, 키워드 포함)"""
580
  def __init__(self):
581
  self.profiles_file = PROFILE_DIR / "profiles.json"
582
  self.profiles = {}
 
601
  def _normalize_email(self, email: str) -> str:
602
  """이메일 정규화 (소문자 변환, 공백 제거)"""
603
  return email.strip().lower()
604
+ def save_profile(self, email: str, profile_data: dict, keywords: List[str] = None) -> Tuple[bool, str]:
605
+ """프로필 저장 (키워드 포함)"""
606
  if not email or '@' not in email:
607
  return False, "올바른 이메일 주소를 입력해주세요."
608
  email_key = self._normalize_email(email)
609
+
610
+ # 키워드 정리 (최대 5개, 빈 문자열 제거 후 저장)
611
+ clean_keywords = []
612
+ if keywords:
613
+ clean_keywords = [kw.strip() for kw in keywords if kw and kw.strip()][:5]
614
+
615
  self.profiles[email_key] = {
616
  "email": email_key,
617
  "profile": profile_data,
618
+ "keywords": clean_keywords, # ⭐ 키워드 추가
619
  "updated_at": datetime.now(KST).isoformat(),
620
  "created_at": self.profiles.get(email_key, {}).get("created_at", datetime.now(KST).isoformat())
621
  }
622
  self._save_profiles()
623
+ kw_str = ", ".join(clean_keywords) if clean_keywords else "없음"
624
+ logger.info(f"Profile saved for: {email_key} (keywords: {kw_str})")
625
+ return True, f"✅ 프로필이 저장되었습니다. ({email_key}, 키워드 {len(clean_keywords)}개)"
626
+ def load_profile(self, email: str) -> Tuple[Optional[dict], str, List[str]]:
627
+ """프로필 로드 (키워드 포함) - 3개 값 반환"""
628
  if not email or '@' not in email:
629
+ return None, "올바른 이메일 주소를 입력해주세요.", []
630
  email_key = self._normalize_email(email)
631
  if email_key in self.profiles:
632
  data = self.profiles[email_key]
633
+ profile = data.get("profile", {})
634
+ keywords = data.get("keywords", [])
635
+ # 키워드가 5개 미만이면 빈 문자열로 패딩
636
+ while len(keywords) < 5:
637
+ keywords.append("")
638
  logger.info(f"Profile loaded for: {email_key}")
639
+ return profile, f"✅ 프로필을 불러왔습니다. (마지막 수정: {data.get('updated_at', '알 수 없음')[:10]})", keywords[:5]
640
+ return None, f"ℹ️ '{email_key}'에 저장된 프로필이 없습니다. 새로 입력해주세요.", []
641
+ def get_profile_keywords(self, email: str) -> List[str]:
642
+ """키워드만 조회"""
643
+ if not email or '@' not in email:
644
+ return []
645
+ email_key = self._normalize_email(email)
646
+ if email_key not in self.profiles:
647
+ return []
648
+ keywords = self.profiles[email_key].get("keywords", [])
649
+ while len(keywords) < 5:
650
+ keywords.append("")
651
+ return keywords[:5]
652
  def delete_profile(self, email: str) -> Tuple[bool, str]:
653
  """프로필 삭제"""
654
  email_key = self._normalize_email(email)
 
660
  def get_profile_count(self) -> int:
661
  """저장된 프로필 수"""
662
  return len(self.profiles)
663
+ def get_all_profiles(self) -> dict:
664
+ """모든 프로필 반환 (관리자용)"""
665
+ return self.profiles
666
  _cache_instance = None
667
  _content_cache_instance = None
668
  _profile_cache_instance = None
 
961
  if __name__ == "__main__":
962
  print("Testing cache system...")
963
  status = initialize_cache_system()
964
+ print(f"Status: {json.dumps(status, ensure_ascii=False, indent=2)}")