feat: 预览并恢复首次 Sync 合并且不丢失笔记链接
This commit is contained in:
@@ -35,6 +35,11 @@ def _refresh():
|
||||
removed = set(old) - {entry['file_id'] for entry in current}
|
||||
# Content is verified before starting the projection transaction. No model/network IO inside.
|
||||
with transaction(conn):
|
||||
task_links = []
|
||||
for entry in current:
|
||||
for alias in entry.get('aliases', []):
|
||||
if alias in removed:
|
||||
task_links.extend((entry['file_id'], row['task_id']) for row in conn.execute('SELECT task_id FROM tasks WHERE note_id=?', [alias]))
|
||||
for file_id in removed:
|
||||
for block_id in repository.delete_note(file_id, conn=conn):
|
||||
conn.execute('DELETE FROM vec_blocks WHERE block_id=?', [block_id])
|
||||
@@ -47,6 +52,8 @@ def _refresh():
|
||||
conn.execute('DELETE FROM vec_blocks WHERE block_id=?', [block_id])
|
||||
conn.execute('UPDATE blocks SET embedding_local_only=? WHERE note_id=?', (int(parsed.embedding_local_only), parsed.note_id))
|
||||
conn.execute('INSERT OR REPLACE INTO host_projection VALUES (?,?,?)', (parsed.note_id, document['hash'], parsed.file_path))
|
||||
for file_id, task_id in task_links:
|
||||
conn.execute('UPDATE tasks SET note_id=? WHERE task_id=? AND note_id IS NULL', [file_id, task_id])
|
||||
if removed or changed:
|
||||
repository.set_index_meta({'workspace_vectors_pending': '1'}, conn=conn)
|
||||
finally:
|
||||
|
||||
@@ -74,3 +74,23 @@ def test_desktop_semantic_rebuild_preserves_host_file_id(tmp_path, monkeypatch):
|
||||
assert [record.note_id for record in repository.list_note_locations()] == ['stable-host-id']
|
||||
finally:
|
||||
host_bridge.vault_id.reset(token)
|
||||
|
||||
|
||||
def test_host_identity_adoption_keeps_existing_task_links(tmp_path, monkeypatch):
|
||||
settings = replace(get_settings(), environment='desktop', data_dir=tmp_path, db_path=tmp_path/'global.sqlite3')
|
||||
monkeypatch.setattr(db, 'get_settings', lambda: settings)
|
||||
monkeypatch.setattr('app.config.get_settings', lambda: settings)
|
||||
document = {'file_id': 'before-merge', 'path': 'same.md', 'hash': sha256(b'test').hexdigest(), 'content': 'test', 'created_at': 0, 'updated_at': 1}
|
||||
monkeypatch.setattr(desktop_notes, 'call', lambda method, **params: {'items': [document], 'total': 1} if method == 'list' else document)
|
||||
from app.services import task_service
|
||||
token = host_bridge.vault_id.set(str(uuid4()))
|
||||
try:
|
||||
task = task_service.create_task(title='Preserve link', note_id='before-merge')
|
||||
document['file_id'] = 'after-merge'
|
||||
document['aliases'] = ['before-merge']
|
||||
asyncio.run(desktop_projection.refresh())
|
||||
assert task_service.get_task(task.task_id).note_id == 'after-merge'
|
||||
assert repository.get_note_record('before-merge') is None
|
||||
assert repository.get_note_record('after-merge') is not None
|
||||
finally:
|
||||
host_bridge.vault_id.reset(token)
|
||||
|
||||
Reference in New Issue
Block a user