perf(execution): consolidate full checks at commit boundaries

This commit is contained in:
阿白叔 committed 2026-10-19 09:41:41 +08:00
1 parent 196c84b0d3
commit 0714c7753f
4 files changed
+241 -24

No files matched your search

+85 -21
View File
@@ -1036,8 +1036,13 @@ Function QPNativeReportShowsMutation(ByVal ReportPath)
End Function
Sub QPRequireSnapshotContext(ByVal SnapshotPath)
Dim Records, Meta
Dim Records
Set Records = QPReadSnapshot(SnapshotPath)
QPRequireRecordsContext Records
End Sub
Sub QPRequireRecordsContext(ByRef Records)
Dim Meta
Set Meta = Records.Item("meta")
If QPCanonicalPath(CStr(Meta("project_path"))) <> QPCanonicalPath(QPProjectPath()) Or _
CStr(Meta("sheet_name")) <> QPSheetIdentity() Then _
@@ -1186,17 +1191,49 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
End Sub
Function QPUntouchedComponent(ByRef Comp)
QPUntouchedComponent = "U" & vbTab & QPEncode(CStr(Comp.UID)) & vbTab & _
QPEncode(CStr(Comp.Refdes)) & vbTab & QPEncode(QPEffectiveComponentAttribute(Comp, "Part Number")) & vbTab & _
QPEncode(QPEffectiveComponentAttribute(Comp, "Value")) & vbTab & _
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Name")) & vbTab & _
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Label")) & vbCrLf
QPUntouchedComponent = QPUntouchedComponent & "G" & vbTab & QPEncode(CStr(Comp.UID)) & _
vbTab & QPEncode(QPUntouchedFullState(Comp)) & vbCrLf
Dim State, Identity, Fields
State = QPUntouchedFullState(Comp)
Identity = QPUntouchedIdentity(State)
Fields = Split(Identity, vbTab)
QPUntouchedComponent = Identity & vbCrLf & "G" & vbTab & Fields(1) & _
vbTab & QPEncode(State) & vbCrLf
End Function
Function QPUntouchedIdentity(ByVal State)
Dim Values, Seen, Line, Fields, Header, Name, Value
Set Values = CreateObject("Scripting.Dictionary")
Set Seen = CreateObject("Scripting.Dictionary")
Values.CompareMode = vbTextCompare
Seen.CompareMode = vbTextCompare
For Each Name In Array("Part Number", "Value", "Part Name", "Part Label")
Values.Add Name, ""
Next
Header = ""
For Each Line In Split(State, vbCrLf)
If Len(Line) > 0 Then
Fields = Split(Line, vbTab)
If Fields(0) = "C" Then
Header = "U" & vbTab & Fields(1) & vbTab & Fields(2)
ElseIf Fields(0) = "A" Then
Name = QPDecode(Fields(2))
If Values.Exists(Name) Then
If Seen.Exists(Name) Then Err.Raise vbObjectError + 874, _
"QuickPartReplace.Target", "duplicate unselected identity attribute"
Seen.Add Name, True
Value = Fields(4)
If Len(Value) = 0 Then Value = Fields(3)
Values(Name) = Value
End If
End If
End If
Next
QPUntouchedIdentity = Header & vbTab & Values("Part Number") & vbTab & _
Values("Value") & vbTab & Values("Part Name") & vbTab & Values("Part Label")
End Function
Function QPUntouchedFullState(ByRef Comp)
Dim Point, Pins, Connections, Attr, AttributeText, Result
Dim Point, Pins, Connections, Attr, AttributeText, Result, Uid
Uid = CStr(Comp.UID)
Set Point = Comp.GetLocation()
Set Pins = QPComponentPins(Comp)
If Pins.Count = 0 Then
@@ -1204,15 +1241,15 @@ Function QPUntouchedFullState(ByRef Comp)
' still propagate. Selected replacement symbols continue to require pins.
Connections = "NO_PINS"
Else
Connections = QPConnectionSignature(Comp)
Connections = QPConnectionSignatureFromPins(Comp, Pins)
End If
Result = "C" & vbTab & QPEncode(CStr(Comp.UID)) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
Result = "C" & vbTab & QPEncode(Uid) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
vbTab & QPEncode(CStr(Point.X)) & vbTab & QPEncode(CStr(Point.Y)) & _
vbTab & QPEncode(CStr(Comp.Orientation)) & vbTab & QPEncode(CStr(Comp.Scale)) & _
vbTab & QPEncode(Connections) & vbCrLf
AttributeText = ""
For Each Attr In Comp.Attributes
AttributeText = AttributeText & QPSnapshotAttribute(CStr(Comp.UID), Attr)
AttributeText = AttributeText & QPSnapshotAttribute(Uid, Attr)
Next
QPUntouchedFullState = Result & QPSortSnapshotLines(AttributeText)
End Function
@@ -1359,7 +1396,7 @@ Function QPSortSnapshotLines(ByVal Text)
End Function
Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
Dim Instance
Dim Instance, Point, ErrorNumber, ErrorDescription
Dim LocationX
Dim LocationY
Dim Color
@@ -1369,8 +1406,16 @@ Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
Dim Visible
Instance = Attr.InstanceValue
LocationX = QPOptionalAttributeField(Attr, "location_x")
LocationY = QPOptionalAttributeField(Attr, "location_y")
On Error Resume Next
Set Point = Attr.GetLocation()
LocationX = CStr(Point.X)
LocationY = CStr(Point.Y)
ErrorNumber = Err.Number
ErrorDescription = Err.Description
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then Err.Raise ErrorNumber, "QuickPartReplace.Snapshot", _
"Cannot capture " & CStr(Attr.Name) & ".location: " & ErrorDescription
Color = QPOptionalAttributeField(Attr, "color")
Font = QPOptionalAttributeField(Attr, "font")
Size = QPOptionalAttributeField(Attr, "size")
@@ -1435,7 +1480,10 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
QPProgress "restore_preflight", 0, 0
Set Records = QPReadSnapshot(SnapshotPath)
QPRequireCommandSnapshot Command, SnapshotPath
QPVerifyUntouched Records
' Owned batches perform full-page checks immediately before saving and
' after disk reopen in QPFinishBatchItem, before publishing completion.
' Manual restoration keeps full checks on both sides of its writes.
If Not QP_BatchMode Then QPVerifyUntouched Records
Set Meta = Records.Item("meta")
If QPCanonicalPath(CStr(Meta("project_path"))) <> QPCanonicalPath(QPProjectPath()) Or _
CStr(Meta("sheet_name")) <> QPSheetIdentity() Then _
@@ -1544,7 +1592,7 @@ Sub QPRestorePlans(ByRef Command, ByRef Records, ByRef Plans)
QPProgress "restore_attributes", Index + 1, Plans.Count
Next
QPVerifyRestoredPlans Command, Records, Plans, ValueStates
QPVerifyUntouched Records
If Not QP_BatchMode Then QPVerifyUntouched Records
End Sub
Sub QPVerifyRestoredPlans(ByRef Command, ByRef Records, ByRef Plans, ByRef ValueStates)
@@ -1657,7 +1705,19 @@ Sub QPRecoverSavedJob(ByRef Command, ByVal SnapshotPath)
Err.Clear
On Error GoTo 0
If ErrorNumber = 0 Then
QPWriteStatus QP_Root, QP_CurrentJobId, "restored_ok", "recovery_verified", "Saved replacement already passes all restoration checks; no CAD writes."
If QP_BatchMode Then
If QP_SessionMode Then Err.Raise vbObjectError + 865, _
"QuickPartReplace.Recovery", "read-only recovery cannot reuse a project session"
' A fresh owned recovery session has already verified the disk state.
' Closing without saving avoids a second save/reopen cycle for no writes.
QPRequireCommandSnapshot Command, SnapshotPath
QPCloseBatchProject CStr(Command("project_path")), False
QP_BatchMode = False
QPWriteStatus QP_Root, QP_CurrentJobId, "restored_ok", "recovery_saved_verified", _
"Saved replacement verified from disk and owned project closed without additional saving."
Else
QPWriteStatus QP_Root, QP_CurrentJobId, "restored_ok", "recovery_verified", "Saved replacement already passes all restoration checks; no CAD writes."
End If
Else
If ErrorNumber <> vbObjectError + 833 And ErrorNumber <> vbObjectError + 834 And _
ErrorNumber <> vbObjectError + 837 And ErrorNumber <> vbObjectError + 840 And _
@@ -2054,7 +2114,7 @@ Sub QPRequireCommandSnapshot(ByRef Command, ByVal SnapshotPath)
Dim Records, Meta
Set Records = QPReadSnapshot(SnapshotPath)
Set Meta = Records.Item("meta")
QPRequireSnapshotContext SnapshotPath
QPRequireRecordsContext Records
If CStr(Meta("old_part_number")) <> CStr(Command("old_part_number")) Or _
CStr(Meta("new_part_number")) <> CStr(Command("new_part_number")) Then _
Err.Raise vbObjectError + 830, "QuickPartReplace", "snapshot rule mismatch"
@@ -2398,6 +2458,11 @@ End Function
Function QPConnectionSignature(ByRef Comp)
Dim Pins
Set Pins = QPComponentPins(Comp)
QPConnectionSignature = QPConnectionSignatureFromPins(Comp, Pins)
End Function
Function QPConnectionSignatureFromPins(ByRef Comp, ByRef Pins)
Dim PinIndexKey
Dim PinReadCount
Dim CmpPin
@@ -2418,7 +2483,6 @@ Function QPConnectionSignature(ByRef Comp)
Set Signatures = CreateObject("Scripting.Dictionary")
QP_Stage = "query_pins"
Set Pins = QPComponentPins(Comp)
PinReadCount = 0
For Each PinIndexKey In Pins.Keys
Set CmpPin = Pins.Item(CStr(PinIndexKey))
@@ -2487,7 +2551,7 @@ Function QPConnectionSignature(ByRef Comp)
For Index = 0 To UBound(Keys)
Result = Result & Signatures.Item(CStr(Keys(Index))) & vbLf
Next
QPConnectionSignature = Result
QPConnectionSignatureFromPins = Result
End Function
Sub QPAddSortedSignature(ByRef Signatures, ByVal PinKey, ByVal PinValue)