Skip to content

Commit 2b13132

Browse files
Make "is map entry tombstoned" check referenced object per RTLM14c
1 parent 5ba64a2 commit 2b13132

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
@@ -136,7 +136,7 @@ internal final class InternalDefaultLiveMap: Sendable {
136136
return convertEntryToLiveMapValue(entry, delegate: delegate)
137137
}
138138

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

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

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

785797
/// 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
@@ -33,7 +33,7 @@ internal final class PublicDefaultLiveMap: LiveMap {
3333

3434
internal var size: Int {
3535
get throws(ARTErrorInfo) {
36-
try proxied.size(coreSDK: coreSDK)
36+
try proxied.size(coreSDK: coreSDK, delegate: delegate)
3737
}
3838
}
3939

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)