Skip to content

Commit ed2c119

Browse files
committed
feat(model-client): added IModelClientV2.pullHash
If you only want to check what the latest version on the server is without receiving all the data of it.
1 parent 2049ba0 commit ed2c119

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/IModelClientV2.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ interface IModelClientV2 {
5353

5454
suspend fun pull(branch: BranchReference, lastKnownVersion: IVersion?): IVersion
5555

56+
suspend fun pullHash(branch: BranchReference): String
57+
5658
suspend fun poll(branch: BranchReference, lastKnownVersion: IVersion?): IVersion
5759
}

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ class ModelClientV2(
165165
return receivedVersion
166166
}
167167

168+
override suspend fun pullHash(branch: BranchReference): String {
169+
val response = httpClient.get {
170+
url {
171+
takeFrom(baseUrl)
172+
appendPathSegmentsEncodingSlash("repositories", branch.repositoryId.id, "branches", branch.branchName, "hash")
173+
}
174+
}
175+
val receivedHash: String = response.body()
176+
// LOG.debug { "${clientId.toString(16)}.pullHash($branch) -> $receivedHash" }
177+
return receivedHash
178+
}
179+
168180
override suspend fun poll(branch: BranchReference, lastKnownVersion: IVersion?): IVersion {
169181
require(lastKnownVersion is CLVersion?)
170182
LOG.debug { "${clientId.toString(16)}.poll($branch, $lastKnownVersion)" }

model-server/src/main/kotlin/org/modelix/model/server/handlers/ModelReplicationServer.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ class ModelReplicationServer(val repositoriesManager: RepositoriesManager) {
127127
}
128128
call.respondDelta(versionHash, baseVersionHash)
129129
}
130+
get("hash") {
131+
val branch = branchRef()
132+
val versionHash = repositoriesManager.getVersionHash(branch)
133+
if (versionHash == null) {
134+
call.respondText(
135+
"Branch '${branch.branchName}' doesn't exist in repository '${branch.repositoryId.id}'",
136+
status = HttpStatusCode.NotFound,
137+
)
138+
return@get
139+
}
140+
call.respondText(versionHash)
141+
}
130142
post {
131143
val deltaFromClient = call.receive<VersionDelta>()
132144
deltaFromClient.checkObjectHashes()

0 commit comments

Comments
 (0)