Add pick_operation to sync with client

This commit is contained in:
WQY\qiong
2022-10-24 21:52:35 +08:00
parent 5597d3afd0
commit 8cfd22e17d
3 changed files with 14 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ from .operation import ChangeSet
from .operation import get_current_operation
from .operation import execute_undo, execute_redo
from .operation import have_snapshot, take_snapshot, pick_snapshot
from .operation import sync_with_server
from .operation import pick_operation, sync_with_server
from .command import execute_batch_commands

View File

@@ -141,12 +141,8 @@ def _get_parents(name: str, id: int) -> list[int]:
return ids
def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
if not have_snapshot(name, tag):
return ChangeSet()
target = int(read(name, f"select id from snapshot_operation where tag = '{tag}'")['id'])
def pick_operation(name: str, operation: int, discard: bool) -> ChangeSet:
target = operation
curr = get_current_operation(name)
curr_parents = _get_parents(name, curr)
@@ -183,6 +179,14 @@ def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
return change.compress()
def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
if not have_snapshot(name, tag):
return ChangeSet()
target = int(read(name, f"select id from snapshot_operation where tag = '{tag}'")['id'])
return pick_operation(name, target, discard)
def _get_change_set(name: str, operation: int, undo: bool) -> dict[str, Any]:
row = read(name, f'select * from operation where id = {operation}')
return eval(row['undo_cs']) if undo else eval(row['redo_cs'])

View File

@@ -131,6 +131,9 @@ def take_snapshot(name: str, tag: str) -> int | None:
def pick_snapshot(name: str, tag: str, discard: bool = False) -> ChangeSet:
return api.pick_snapshot(name, tag, discard)
def pick_operation(name: str, operation: int, discard: bool = False) -> ChangeSet:
return api.pick_operation(name, operation, discard)
def sync_with_server(name: str, operation: int) -> ChangeSet:
return api.sync_with_server(name, operation)