Skip to content

Commit

Permalink
Fixing the non-determinism of endpoint type refs and device type refs…
Browse files Browse the repository at this point in the history
… in the .zap files by removing it for device type refs and using the index for endpoint type id instead of the primary keys of their corresponding tables since they are non deterministic (project-chip#1117)
  • Loading branch information
brdandu authored Aug 30, 2023
1 parent 88ff3e0 commit a75c922
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 21 additions & 1 deletion src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ exports.map = {
}
},

deviceTypeExport: (x) => {
if (x == null) return undefined
return {
code: x.CODE,
profileId: x.PROFILE_ID,
label: x.NAME,
name: x.NAME,
}
},

deviceTypeCluster: (x) => {
if (x == null) return undefined
return {
Expand Down Expand Up @@ -445,6 +455,16 @@ exports.map = {
deviceTypes: x.deviceTypes, // Populated outside the sql query mapping.
}
},
endpointTypeExport: (x) => {
if (x == null) return undefined
return {
id: x.ENDPOINT_TYPE_INDEX, // Index of endpoint type from list of endpoints types based on endpoint identifier
endpointTypeId: x.ENDPOINT_TYPE_ID,
name: x.NAME,
deviceTypeRef: x.DEVICE_TYPE_REF,
deviceTypes: x.deviceTypes, // Populated outside the sql query mapping.
}
},
endpointTypeDevice: (x) => {
if (x == null) return undefined
return {
Expand Down Expand Up @@ -698,7 +718,7 @@ exports.map = {
severity: x.NOTICE_SEVERITY,
id: x.NOTICE_ID,
}
}
},
}

exports.reverseMap = {
Expand Down
8 changes: 4 additions & 4 deletions src-electron/db/query-impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ async function exportEndpointTypes(db, sessionId) {
`
SELECT
ENDPOINT_TYPE.ENDPOINT_TYPE_ID,
ENDPOINT_TYPE.NAME
ENDPOINT_TYPE.NAME,
ROW_NUMBER() OVER(ORDER BY ENDPOINT.ENDPOINT_IDENTIFIER) AS ENDPOINT_TYPE_INDEX
FROM
ENDPOINT_TYPE
LEFT JOIN
Expand All @@ -138,7 +139,7 @@ ORDER BY
ENDPOINT_TYPE.NAME`,
[sessionId]
)
.then((rows) => rows.map(dbMapping.map.endpointType))
.then((rows) => rows.map(dbMapping.map.endpointTypeExport))

//Associate each endpoint type to the device types
for (let i = 0; i < endpointTypes.length; i++) {
Expand Down Expand Up @@ -172,10 +173,9 @@ ORDER BY
)

// Updating the device type info for the endpoint
endpointTypes[i].deviceTypeRefs = rows.map((x) => x.DEVICE_TYPE_ID)
endpointTypes[i].deviceVersions = rows.map((x) => x.DEVICE_VERSION)
endpointTypes[i].deviceIdentifiers = rows.map((x) => x.CODE)
endpointTypes[i].deviceTypes = rows.map(dbMapping.map.deviceType)
endpointTypes[i].deviceTypes = rows.map(dbMapping.map.deviceTypeExport)

// Loading endpointTypeRef as primary endpointType for backwards compatibility
endpointTypes[i].deviceTypeRef = endpointTypes[i].deviceTypes[0]
Expand Down

0 comments on commit a75c922

Please sign in to comment.