Code refactor for command
This commit is contained in:
@@ -290,7 +290,7 @@ def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def cache_add_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
def cache_add_command(name: str, cs: ChangeSet) -> DbChangeSet | None:
|
||||||
type = cs.operations[0]['type']
|
type = cs.operations[0]['type']
|
||||||
|
|
||||||
if type == _s1_title:
|
if type == _s1_title:
|
||||||
@@ -359,7 +359,7 @@ def cache_add_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cache_update_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
def cache_update_command(name: str, cs: ChangeSet) -> DbChangeSet | None:
|
||||||
type = cs.operations[0]['type']
|
type = cs.operations[0]['type']
|
||||||
|
|
||||||
if type == _s1_title:
|
if type == _s1_title:
|
||||||
@@ -378,8 +378,8 @@ def cache_update_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
|||||||
return set_valve_cache(name, cs)
|
return set_valve_cache(name, cs)
|
||||||
elif type == _s8_tag:
|
elif type == _s8_tag:
|
||||||
return set_tag_cache(name, cs)
|
return set_tag_cache(name, cs)
|
||||||
elif type == _s9_demand: # exception, batch command ...
|
elif type == _s9_demand:
|
||||||
return None
|
return set_demand_cache(name, cs)
|
||||||
elif type == _s10_status:
|
elif type == _s10_status:
|
||||||
return set_status_cache(name, cs)
|
return set_status_cache(name, cs)
|
||||||
elif type == _s11_pattern:
|
elif type == _s11_pattern:
|
||||||
@@ -428,7 +428,7 @@ def cache_update_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cache_delete_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
def cache_delete_command(name: str, cs: ChangeSet) -> DbChangeSet | None:
|
||||||
type = cs.operations[0]['type']
|
type = cs.operations[0]['type']
|
||||||
|
|
||||||
if type == _s1_title:
|
if type == _s1_title:
|
||||||
@@ -498,10 +498,10 @@ def cache_delete_command(name: str, cs: ChangeSet) -> SqlChangeSet | None:
|
|||||||
|
|
||||||
|
|
||||||
def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
|
def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
redo_sql_s = []
|
redo_sql_s : list[str] = []
|
||||||
undo_sql_s = []
|
undo_sql_s : list[str] = []
|
||||||
redo_cs_s = []
|
redo_cs_s : list[dict[str, Any]] = []
|
||||||
undo_cs_s = []
|
undo_cs_s : list[dict[str, Any]] = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for op in cs.operations:
|
for op in cs.operations:
|
||||||
@@ -513,8 +513,6 @@ def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
r = cache_add_command(name, ChangeSet(op))
|
r = cache_add_command(name, ChangeSet(op))
|
||||||
elif operation == API_UPDATE:
|
elif operation == API_UPDATE:
|
||||||
r = cache_update_command(name, ChangeSet(op))
|
r = cache_update_command(name, ChangeSet(op))
|
||||||
if op['type'] == 'demand':
|
|
||||||
r = set_demand_cache(name, ChangeSet(op))
|
|
||||||
elif operation == API_DELETE:
|
elif operation == API_DELETE:
|
||||||
r = cache_delete_command(name, ChangeSet(op))
|
r = cache_delete_command(name, ChangeSet(op))
|
||||||
|
|
||||||
@@ -522,18 +520,10 @@ def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
print(f'ERROR: Build [{op}] returns None')
|
print(f'ERROR: Build [{op}] returns None')
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
|
|
||||||
if op['type'] == 'demand':
|
redo_sql_s.append(r.redo_sql)
|
||||||
redo_sql_s.append(r.redo_sql)
|
undo_sql_s.append(r.undo_sql)
|
||||||
undo_sql_s.append(r.undo_sql)
|
redo_cs_s += r.redo_cs
|
||||||
for d in r.redo_cs:
|
undo_cs_s += r.undo_cs
|
||||||
redo_cs_s.append(d)
|
|
||||||
for d in r.undo_cs.reverse(): # need reverse again...
|
|
||||||
undo_cs_s.append(r.undo_cs)
|
|
||||||
else:
|
|
||||||
redo_sql_s.append(r.redo_sql)
|
|
||||||
undo_sql_s.append(r.undo_sql)
|
|
||||||
redo_cs_s.append(r.redo_cs)
|
|
||||||
undo_cs_s.append(r.undo_cs)
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -546,6 +536,6 @@ def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
undo_cs_s.reverse()
|
undo_cs_s.reverse()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return execute_batch(name, redo_sql, undo_sql, redo_cs_s, undo_cs_s)
|
return execute_command(name, DbChangeSet(redo_sql, undo_sql, redo_cs_s, undo_cs_s))
|
||||||
except:
|
except:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
|
|||||||
Reference in New Issue
Block a user