mirror of
https://github.com/mruwnik/memory.git
synced 2025-07-30 06:36:07 +02:00
proper notes path
This commit is contained in:
parent
288c2995e5
commit
50601ad930
@ -105,7 +105,7 @@ COMIC_SYNC_INTERVAL = int(os.getenv("COMIC_SYNC_INTERVAL", 60 * 60 * 24))
|
|||||||
ARTICLE_FEED_SYNC_INTERVAL = int(os.getenv("ARTICLE_FEED_SYNC_INTERVAL", 30 * 60))
|
ARTICLE_FEED_SYNC_INTERVAL = int(os.getenv("ARTICLE_FEED_SYNC_INTERVAL", 30 * 60))
|
||||||
CLEAN_COLLECTION_INTERVAL = int(os.getenv("CLEAN_COLLECTION_INTERVAL", 24 * 60 * 60))
|
CLEAN_COLLECTION_INTERVAL = int(os.getenv("CLEAN_COLLECTION_INTERVAL", 24 * 60 * 60))
|
||||||
CHUNK_REINGEST_INTERVAL = int(os.getenv("CHUNK_REINGEST_INTERVAL", 60 * 60))
|
CHUNK_REINGEST_INTERVAL = int(os.getenv("CHUNK_REINGEST_INTERVAL", 60 * 60))
|
||||||
NOTES_SYNC_INTERVAL = int(os.getenv("NOTES_SYNC_INTERVAL", 15))
|
NOTES_SYNC_INTERVAL = int(os.getenv("NOTES_SYNC_INTERVAL", 15 * 60))
|
||||||
|
|
||||||
CHUNK_REINGEST_SINCE_MINUTES = int(os.getenv("CHUNK_REINGEST_SINCE_MINUTES", 60 * 24))
|
CHUNK_REINGEST_SINCE_MINUTES = int(os.getenv("CHUNK_REINGEST_SINCE_MINUTES", 60 * 24))
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ def sync_note(
|
|||||||
note_type: str | None = None,
|
note_type: str | None = None,
|
||||||
confidences: dict[str, float] = {},
|
confidences: dict[str, float] = {},
|
||||||
tags: list[str] = [],
|
tags: list[str] = [],
|
||||||
|
save_to_file: bool = True,
|
||||||
):
|
):
|
||||||
logger.info(f"Syncing note {subject}")
|
logger.info(f"Syncing note {subject}")
|
||||||
text = Note.as_text(content, subject)
|
text = Note.as_text(content, subject)
|
||||||
@ -123,10 +124,11 @@ def sync_note(
|
|||||||
note.tags = tags # type: ignore
|
note.tags = tags # type: ignore
|
||||||
|
|
||||||
note.update_confidences(confidences)
|
note.update_confidences(confidences)
|
||||||
with git_tracking(
|
if save_to_file:
|
||||||
settings.NOTES_STORAGE_DIR, f"Sync note {filename}: {subject}"
|
with git_tracking(
|
||||||
):
|
settings.NOTES_STORAGE_DIR, f"Sync note {filename}: {subject}"
|
||||||
note.save_to_file()
|
):
|
||||||
|
note.save_to_file()
|
||||||
return process_content_item(note, session)
|
return process_content_item(note, session)
|
||||||
|
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ def sync_notes(folder: str):
|
|||||||
sync_note.delay(
|
sync_note.delay(
|
||||||
subject=filename.stem,
|
subject=filename.stem,
|
||||||
content=filename.read_text(),
|
content=filename.read_text(),
|
||||||
filename=filename.as_posix(),
|
filename=filename.relative_to(path).as_posix(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -207,19 +209,25 @@ def track_git_changes():
|
|||||||
)
|
)
|
||||||
if diff_result and diff_result.returncode == 0:
|
if diff_result and diff_result.returncode == 0:
|
||||||
changed_files = [
|
changed_files = [
|
||||||
f.strip() for f in diff_result.stdout.strip().split("\n") if f.strip()
|
filename
|
||||||
|
for f in diff_result.stdout.strip().split("\n")
|
||||||
|
if (filename := f.strip()) and filename.endswith(".md")
|
||||||
]
|
]
|
||||||
logger.info(f"Changed files: {changed_files}")
|
logger.info(f"Changed files: {changed_files}")
|
||||||
else:
|
else:
|
||||||
logger.error("Failed to get changed files")
|
logger.error("Failed to get changed files")
|
||||||
return {"status": "error", "error": "Failed to get changed files"}
|
return {"status": "error", "error": "Failed to get changed files"}
|
||||||
|
|
||||||
for file in changed_files:
|
for filename in changed_files:
|
||||||
file = pathlib.Path(file)
|
file = settings.NOTES_STORAGE_DIR / filename
|
||||||
|
if not file.exists():
|
||||||
|
logger.warning(f"File not found: {filename}")
|
||||||
|
continue
|
||||||
sync_note.delay(
|
sync_note.delay(
|
||||||
subject=file.stem,
|
subject=file.stem,
|
||||||
content=file.read_text(),
|
content=file.read_text(),
|
||||||
filename=file.as_posix(),
|
filename=filename,
|
||||||
|
save_to_file=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -695,71 +695,6 @@ def test_track_git_changes_no_changes(
|
|||||||
mock_sync_note.delay.assert_not_called()
|
mock_sync_note.delay.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@patch("memory.workers.tasks.notes.sync_note")
|
|
||||||
@patch("memory.workers.tasks.notes.git_command")
|
|
||||||
@patch("memory.workers.tasks.notes.check_git_command")
|
|
||||||
@patch("memory.workers.tasks.notes.settings")
|
|
||||||
def test_track_git_changes_with_changes_success(
|
|
||||||
mock_settings, mock_check_git, mock_git_command, mock_sync_note
|
|
||||||
):
|
|
||||||
"""Test track_git_changes when there are changes and diff succeeds."""
|
|
||||||
# Mock git repo exists
|
|
||||||
mock_repo_root = Mock()
|
|
||||||
mock_repo_root.__truediv__ = Mock(return_value=Mock())
|
|
||||||
mock_repo_root.__truediv__.return_value.exists.return_value = True
|
|
||||||
mock_settings.NOTES_STORAGE_DIR = mock_repo_root
|
|
||||||
|
|
||||||
# Mock git commands
|
|
||||||
mock_check_git.side_effect = [
|
|
||||||
"main", # current branch
|
|
||||||
"abc123", # current commit
|
|
||||||
None, # fetch origin
|
|
||||||
"def456", # latest commit (different from current)
|
|
||||||
]
|
|
||||||
|
|
||||||
# Mock pull command
|
|
||||||
mock_git_command.side_effect = [
|
|
||||||
Mock(), # pull command
|
|
||||||
Mock(returncode=0, stdout="file1.md\nfile2.md\n"), # diff command
|
|
||||||
]
|
|
||||||
|
|
||||||
# Mock file reading
|
|
||||||
mock_file1 = Mock()
|
|
||||||
mock_file1.stem = "file1"
|
|
||||||
mock_file1.read_text.return_value = "Content of file 1"
|
|
||||||
mock_file1.as_posix.return_value = "file1.md"
|
|
||||||
|
|
||||||
mock_file2 = Mock()
|
|
||||||
mock_file2.stem = "file2"
|
|
||||||
mock_file2.read_text.return_value = "Content of file 2"
|
|
||||||
mock_file2.as_posix.return_value = "file2.md"
|
|
||||||
|
|
||||||
with patch("memory.workers.tasks.notes.pathlib.Path") as mock_path:
|
|
||||||
mock_path.side_effect = [mock_file1, mock_file2]
|
|
||||||
|
|
||||||
result = notes.track_git_changes()
|
|
||||||
|
|
||||||
assert result == {
|
|
||||||
"status": "success",
|
|
||||||
"current_commit": "abc123",
|
|
||||||
"latest_commit": "def456",
|
|
||||||
"changed_files": ["file1.md", "file2.md"],
|
|
||||||
}
|
|
||||||
|
|
||||||
# Should call sync_note for each changed file
|
|
||||||
assert mock_sync_note.delay.call_count == 2
|
|
||||||
mock_sync_note.delay.assert_any_call(
|
|
||||||
subject="file1",
|
|
||||||
content="Content of file 1",
|
|
||||||
filename="file1.md",
|
|
||||||
)
|
|
||||||
mock_sync_note.delay.assert_any_call(
|
|
||||||
subject="file2",
|
|
||||||
content="Content of file 2",
|
|
||||||
filename="file2.md",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@patch("memory.workers.tasks.notes.sync_note")
|
@patch("memory.workers.tasks.notes.sync_note")
|
||||||
@patch("memory.workers.tasks.notes.git_command")
|
@patch("memory.workers.tasks.notes.git_command")
|
||||||
@patch("memory.workers.tasks.notes.check_git_command")
|
@patch("memory.workers.tasks.notes.check_git_command")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user