Skip to content

Commit 7a42b3a

Browse files
Make "is map entry tombstoned" check referenced object per RTLM14c
1 parent e31f65e commit 7a42b3a

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ internal final class InternalDefaultLiveMap: Sendable {
138138
return convertEntryToLiveMapValue(entry, delegate: delegate)
139139
}
140140

141-
internal func size(coreSDK: CoreSDK) throws(ARTErrorInfo) -> Int {
141+
internal func size(coreSDK: CoreSDK, delegate: LiveMapObjectPoolDelegate) throws(ARTErrorInfo) -> Int {
142142
// RTLM10c: If the channel is in the DETACHED or FAILED state, the library should throw an ErrorInfo error with statusCode 400 and code 90001
143143
let currentChannelState = coreSDK.channelState
144144
if currentChannelState == .detached || currentChannelState == .failed {
@@ -152,7 +152,7 @@ internal final class InternalDefaultLiveMap: Sendable {
152152
return mutex.withLock {
153153
// RTLM10d: Returns the number of non-tombstoned entries (per RTLM14) in the internal data map
154154
mutableState.data.values.count { entry in
155-
!Self.isEntryTombstoned(entry)
155+
!Self.isEntryTombstoned(entry, delegate: delegate)
156156
}
157157
}
158158
}
@@ -173,7 +173,7 @@ internal final class InternalDefaultLiveMap: Sendable {
173173
// RTLM11d1: Pairs with tombstoned entries (per RTLM14) are not returned
174174
var result: [(key: String, value: InternalLiveMapValue)] = []
175175

176-
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry) {
176+
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry, delegate: delegate) {
177177
// Convert entry to LiveMapValue using the same logic as get(key:)
178178
if let value = convertEntryToLiveMapValue(entry, delegate: delegate) {
179179
result.append((key: key, value: value))
@@ -779,9 +779,21 @@ internal final class InternalDefaultLiveMap: Sendable {
779779
// MARK: - Helper Methods
780780

781781
/// Returns whether a map entry should be considered tombstoned, per the check described in RTLM14.
782-
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry) -> Bool {
783-
// RTLM14a, RTLM14b
784-
entry.tombstone == true
782+
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry, delegate: LiveMapObjectPoolDelegate) -> Bool {
783+
// RTLM14a
784+
if entry.tombstone {
785+
return true
786+
}
787+
788+
// RTLM14c
789+
if let objectId = entry.data.objectId {
790+
if let poolEntry = delegate.getObjectFromPool(id: objectId), poolEntry.isTombstone {
791+
return false
792+
}
793+
}
794+
795+
// RTLM14b
796+
return false
785797
}
786798

787799
/// Converts an InternalObjectsMapEntry to LiveMapValue using the same logic as get(key:)

Sources/AblyLiveObjects/Public/Public Proxy Objects/PublicDefaultLiveMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal final class PublicDefaultLiveMap: LiveMap {
3434

3535
internal var size: Int {
3636
get throws(ARTErrorInfo) {
37-
try proxied.size(coreSDK: coreSDK)
37+
try proxied.size(coreSDK: coreSDK, delegate: delegate)
3838
}
3939
}
4040

Tests/AblyLiveObjectsTests/InternalDefaultLiveMapTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ struct InternalDefaultLiveMapTests {
260260

261261
// Define actions to test
262262
let actions: [(String, () throws -> Any)] = [
263-
("size", { try map.size(coreSDK: coreSDK) }),
263+
("size", { try map.size(coreSDK: coreSDK, delegate: delegate) }),
264264
("entries", { try map.entries(coreSDK: coreSDK, delegate: delegate) }),
265265
("keys", { try map.keys(coreSDK: coreSDK, delegate: delegate) }),
266266
("values", { try map.values(coreSDK: coreSDK, delegate: delegate) }),
@@ -306,7 +306,7 @@ struct InternalDefaultLiveMapTests {
306306
)
307307

308308
// Test size - should only count non-tombstoned entries
309-
let size = try map.size(coreSDK: coreSDK)
309+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
310310
#expect(size == 1)
311311

312312
// Test entries - should only return non-tombstoned entries
@@ -348,7 +348,7 @@ struct InternalDefaultLiveMapTests {
348348
clock: MockSimpleClock(),
349349
)
350350

351-
let size = try map.size(coreSDK: coreSDK)
351+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
352352
let entries = try map.entries(coreSDK: coreSDK, delegate: delegate)
353353
let keys = try map.keys(coreSDK: coreSDK, delegate: delegate)
354354
let values = try map.values(coreSDK: coreSDK, delegate: delegate)
@@ -396,7 +396,7 @@ struct InternalDefaultLiveMapTests {
396396
clock: MockSimpleClock(),
397397
)
398398

399-
let size = try map.size(coreSDK: coreSDK)
399+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
400400
let entries = try map.entries(coreSDK: coreSDK, delegate: delegate)
401401
let keys = try map.keys(coreSDK: coreSDK, delegate: delegate)
402402
let values = try map.values(coreSDK: coreSDK, delegate: delegate)

0 commit comments

Comments
 (0)