* Synchronize the existing state to the underlying database.
()
| 1089 | * Synchronize the existing state to the underlying database. |
| 1090 | */ |
| 1091 | private async sync(): Promise<void> { |
| 1092 | const table = await this.controlTable; |
| 1093 | |
| 1094 | // Construct a serializable map of hashes to manifests. |
| 1095 | const manifests: ManifestMap = {}; |
| 1096 | this.versions.forEach((version, hash) => { |
| 1097 | manifests[hash] = version.manifest; |
| 1098 | }); |
| 1099 | |
| 1100 | // Construct a serializable map of client ids to version hashes. |
| 1101 | const assignments: ClientAssignments = {}; |
| 1102 | this.clientVersionMap.forEach((hash, clientId) => { |
| 1103 | assignments[clientId] = hash; |
| 1104 | }); |
| 1105 | |
| 1106 | // Record the latest entry. Since this is a sync which is necessarily happening after |
| 1107 | // initialization, latestHash should always be valid. |
| 1108 | const latest: LatestEntry = { |
| 1109 | latest: this.latestHash!, |
| 1110 | }; |
| 1111 | |
| 1112 | // Synchronize all of these. |
| 1113 | await Promise.all([ |
| 1114 | table.write('manifests', manifests), |
| 1115 | table.write('assignments', assignments), |
| 1116 | table.write('latest', latest), |
| 1117 | ]); |
| 1118 | } |
| 1119 | |
| 1120 | async cleanupCaches(): Promise<void> { |
| 1121 | try { |
no test coverage detected