perf(lastleg): batch appointment requirement generation reads
This commit is contained in:
+2
-2
@@ -117,7 +117,7 @@ public class AppointmentWorkFactAdapter implements AppointmentWorkFactGateway {
|
||||
private String summary() { return "calls="+calls+",requests="+requests+",ms="+millis(); }
|
||||
}
|
||||
/** 每次生成建立独立读取器;没有实际需求读取时不引入原业务依赖。 */
|
||||
public RequirementReader openRequirements() {
|
||||
public RequirementReader openRequirements(List<RequirementInput> inputs) {
|
||||
return new RequirementReader() {
|
||||
private RequirementReader reader;
|
||||
/** 首次实际读取才取得原域作用域,保留每份需求的完整性校验。 */
|
||||
@@ -125,7 +125,7 @@ public class AppointmentWorkFactAdapter implements AppointmentWorkFactGateway {
|
||||
if(reader==null) {
|
||||
var provider=requirements.getIfAvailable();
|
||||
if(provider==null) throw unavailable("原预约需求与批次清单适配尚未接入,不能生成不完整工作清单");
|
||||
reader=provider.openRequirements();
|
||||
reader=provider.openRequirements(inputs);
|
||||
}
|
||||
var result=reader.read(source,effectiveFlow);
|
||||
if(result==null || result.isEmpty()) throw unavailable("原预约需求清单缺失,不能以空清单完成路线生成");
|
||||
|
||||
+3
-2
@@ -28,7 +28,7 @@ public interface AppointmentWorkFactGateway {
|
||||
SourcePage discover(String after, int size);
|
||||
ContainerSource container(String containerBookingId);
|
||||
/** 建立本次原预约需求读取作用域,保持完整批次及明确替代关系。 */
|
||||
RequirementReader openRequirements();
|
||||
RequirementReader openRequirements(List<RequirementInput> inputs);
|
||||
Map<String, Fact> facts(List<AppointmentWorkState> states);
|
||||
Owner owner(String id, Actor actor);
|
||||
Responsibility supplier(String id);
|
||||
@@ -43,5 +43,6 @@ public interface AppointmentWorkFactGateway {
|
||||
interface SupplierDirectory { Responsibility activeSupplier(String id); }
|
||||
/** 单次生成显式复用目录,不跨请求保存来源事实。 */
|
||||
interface RequirementReader { List<Requirement> read(ContainerSource source,Flow effectiveFlow); }
|
||||
interface RequirementProvider { RequirementReader openRequirements(); }
|
||||
record RequirementInput(ContainerSource source,Flow flow) { }
|
||||
interface RequirementProvider { RequirementReader openRequirements(List<RequirementInput> inputs); }
|
||||
}
|
||||
|
||||
+11
-2
@@ -36,7 +36,16 @@ public class AppointmentWorkSyncService {
|
||||
timing.next(SyncPhase.GENERATE);
|
||||
// 保留全部历史与稳定键顺序;逐柜更新立即进入本次工作集,不跨事务缓存。
|
||||
var known=workingSet();
|
||||
var requirementReader=gateway.openRequirements();
|
||||
var requirementInputs=page.containers().stream().filter(source->{
|
||||
// 坏来源仍由下面原顺序校验并报错,不能在后页原料提示阶段抢先覆盖前柜错误。
|
||||
try { validateSource(source);return true; } catch(RuntimeException invalid) { return false; }
|
||||
}).map(source->{
|
||||
var flow=known.values().stream().filter(s->source.containerBookingId().equals(s.getContainerBookingId()) || s.getContainers().stream().anyMatch(c->source.containerBookingId().equals(c.containerBookingId())))
|
||||
.filter(s->s.getType()!=Type.ROUTE && !s.isRetired()).map(AppointmentWorkState::getFlow).findFirst().orElse(source.establishedFlow());
|
||||
return new RequirementInput(source,flow);
|
||||
}).filter(input->input.flow()!=Flow.UNKNOWN).toList();
|
||||
// 提示仅用于原料批量读取,下面逐柜 existing/activeFlow 仍根据最新工作集决定。
|
||||
var requirementReader=gateway.openRequirements(requirementInputs);
|
||||
int created=0; var ids=new HashSet<String>();
|
||||
for(var source:page.containers()) {
|
||||
validateSource(source);
|
||||
@@ -131,7 +140,7 @@ public class AppointmentWorkSyncService {
|
||||
}
|
||||
/** 命令入口仍在调用方守卫事务中即时加载工作集。 */
|
||||
List<String> generate(ContainerSource source,Flow flow,List<AppointmentWorkState> existing,Actor actor) {
|
||||
return generate(source,flow,existing,actor,workingSet(),gateway.openRequirements());
|
||||
return generate(source,flow,existing,actor,workingSet(),gateway.openRequirements(List.of(new RequirementInput(source,flow))));
|
||||
}
|
||||
/** 与持久层全量读取保持稳定键顺序,并保留退役事项及原读取上限。 */
|
||||
private Map<String,AppointmentWorkState> workingSet() {
|
||||
|
||||
Reference in New Issue
Block a user