This commit is contained in:
2026-01-16 20:16:10 -08:00
parent a4d44e6190
commit 3a7c443004

View File

@@ -1858,6 +1858,51 @@ class API_folder_store:
return None
return None
def get_notes(self, file_hash: str) -> Dict[str, str]:
"""Return all named notes for a file hash."""
normalized_hash = str(file_hash or "").strip().lower()
if len(normalized_hash) != 64:
return {}
notes: Dict[str, str] = {}
max_attempts = 5
import time
for attempt in range(max_attempts):
try:
with self._with_db_lock():
cursor = self.connection.cursor()
cursor.execute(
"SELECT name, note FROM note WHERE hash = ?",
(normalized_hash,
),
)
rows = cursor.fetchall() or []
for row in rows:
note_name = str(row[0] or "").strip()
if not note_name:
continue
notes[note_name] = str(row[1] or "")
return notes
except sqlite3.OperationalError as e:
msg = str(e or "").lower()
if "database is locked" in msg and attempt < (max_attempts - 1):
sleep_time = min(0.1 * (2 ** attempt), 1.0)
time.sleep(sleep_time)
continue
logger.error(
f"Error getting notes for hash {file_hash}: {e}",
exc_info=True
)
return {}
except Exception as e:
logger.error(
f"Error getting notes for hash {file_hash}: {e}",
exc_info=True
)
return {}
return {}
def set_note_by_hash(self, file_hash: str, name: str, note: str) -> None:
"""Set a named note using a known file hash (no re-hash)."""
note_name = str(name or "").strip()