diff --git a/src/memory/common/settings.py b/src/memory/common/settings.py index 4333bc0..53c343e 100644 --- a/src/memory/common/settings.py +++ b/src/memory/common/settings.py @@ -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)) CLEAN_COLLECTION_INTERVAL = int(os.getenv("CLEAN_COLLECTION_INTERVAL", 24 * 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)) diff --git a/src/memory/workers/tasks/notes.py b/src/memory/workers/tasks/notes.py index 42a80df..0e2f818 100644 --- a/src/memory/workers/tasks/notes.py +++ b/src/memory/workers/tasks/notes.py @@ -85,6 +85,7 @@ def sync_note( note_type: str | None = None, confidences: dict[str, float] = {}, tags: list[str] = [], + save_to_file: bool = True, ): logger.info(f"Syncing note {subject}") text = Note.as_text(content, subject) @@ -123,10 +124,11 @@ def sync_note( note.tags = tags # type: ignore note.update_confidences(confidences) - with git_tracking( - settings.NOTES_STORAGE_DIR, f"Sync note {filename}: {subject}" - ): - note.save_to_file() + if save_to_file: + with git_tracking( + settings.NOTES_STORAGE_DIR, f"Sync note {filename}: {subject}" + ): + note.save_to_file() return process_content_item(note, session) @@ -145,7 +147,7 @@ def sync_notes(folder: str): sync_note.delay( subject=filename.stem, content=filename.read_text(), - filename=filename.as_posix(), + filename=filename.relative_to(path).as_posix(), ) return { @@ -214,12 +216,16 @@ def track_git_changes(): logger.error("Failed to get changed files") return {"status": "error", "error": "Failed to get changed files"} - for file in changed_files: - file = pathlib.Path(file) + for filename in changed_files: + file = settings.NOTES_STORAGE_DIR / filename + if not file.exists(): + logger.warning(f"File not found: {filename}") + continue sync_note.delay( subject=file.stem, content=file.read_text(), - filename=file.as_posix(), + filename=filename, + save_to_file=False, ) return { diff --git a/tests/memory/workers/tasks/test_notes_tasks.py b/tests/memory/workers/tasks/test_notes_tasks.py index 51de922..799185c 100644 --- a/tests/memory/workers/tasks/test_notes_tasks.py +++ b/tests/memory/workers/tasks/test_notes_tasks.py @@ -695,71 +695,6 @@ def test_track_git_changes_no_changes( 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.git_command") @patch("memory.workers.tasks.notes.check_git_command")