Conversation
WalkthroughThis pull request introduces significant changes to the Realtime subscription system, updates team member role handling, and removes an enum type. The Realtime.swift file is refactored to use slot-centric subscription state with per-slot query handling instead of global channel management. The subscription methods now accept an optional Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/examples/databases/create-operations.md (1)
12-22:⚠️ Potential issue | 🔴 CriticalInvalid Swift syntax in operations parameter.
The
operationsparameter uses JSON notation (curly braces{}) instead of Swift dictionary syntax (square brackets[]). This code will not compile.🐛 Proposed fix for Swift dictionary syntax
let transaction = try await databases.createOperations( transactionId: "<TRANSACTION_ID>", operations: [ - { + [ "action": "create", "databaseId": "<DATABASE_ID>", "collectionId": "<COLLECTION_ID>", "documentId": "<DOCUMENT_ID>", "data": { "name": "Walter O'Brien" } - } + ] ] // optional )Note: The nested
datadictionary will also need to use Swift syntax:["name": "Walter O'Brien"]Sources/Appwrite/Services/Realtime.swift (1)
239-251:⚠️ Potential issue | 🟠 Major
subCallDepthis read outside theconnectSyncqueue — data race.
subCallDepthis incremented/decremented insideconnectSync.sync(lines 240, 250) but read without synchronization on line 245. This can lead to a data race when multiplesubscribecalls execute concurrently.🐛 Proposed fix
- if self.subCallDepth == 1 { - try await self.createSocket() - } - - connectSync.sync { - self.subCallDepth -= 1 - } + let shouldCreateSocket = connectSync.sync { () -> Bool in + let result = self.subCallDepth == 1 + self.subCallDepth -= 1 + return result + } + + if shouldCreateSocket { + try await self.createSocket() + }
🤖 Fix all issues with AI agents
In `@docs/examples/locale/get.md`:
- Line 10: The example shadows the Locale service instance by assigning the
result of calling locale.get() back to the same name; rename the result variable
(e.g., localeResult or foundLocale) so it doesn't collide with the service
instance and update any subsequent references to use the new variable name when
working with the returned value from locale.get().
In `@Sources/Appwrite/Services/Realtime.swift`:
- Around line 370-375: The code force-unwraps data["timestamp"] when
constructing RealtimeResponseEvent (timestamp: data["timestamp"] as! String)
which can crash; change to a safe unwrap/cast (e.g., guard let timestamp =
data["timestamp"] as? String else { handle error/return } or provide a default)
and use that timestamp variable when building the RealtimeResponseEvent to match
the safe unwrapping pattern used for events/channels/payload.
🧹 Nitpick comments (2)
Sources/Appwrite/Services/Realtime.swift (1)
302-317:"connected"should be a named constant like the other message types.
TYPE_ERROR,TYPE_EVENT, andTYPE_PONGare defined as private constants (lines 8–10), but"connected"on line 309 is an inline string literal. Consider adding aTYPE_CONNECTEDconstant for consistency and to prevent typo-related bugs.♻️ Proposed fix
Add at the top with the other constants:
private let TYPE_PONG = "pong" +private let TYPE_CONNECTED = "connected"Then use it in the switch:
- case "connected": + case TYPE_CONNECTED:docs/examples/tablesdb/increment-row-column.md (1)
14-14: Consider using a placeholder like"<COLUMN>"instead of an empty string forcolumn.Other required parameters in this example (and across the docs) use the
<PLACEHOLDER>convention (e.g.,"<DATABASE_ID>"). An empty string for a required parameter could confuse users into thinking it's a valid value.📝 Suggested change
- column: "", + column: "<COLUMN>",
| @@ -8,3 +9,4 @@ let locale = Locale(client) | |||
|
|
|||
| let locale = try await locale.get() | |||
There was a problem hiding this comment.
Fix variable shadowing in the example.
Line 10 reuses the variable name locale, which shadows the Locale service instance declared on Line 8. This code would not compile.
🐛 Proposed fix
-let locale = try await locale.get()
+let userLocale = try await locale.get()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let locale = try await locale.get() | |
| let userLocale = try await locale.get() |
🤖 Prompt for AI Agents
In `@docs/examples/locale/get.md` at line 10, The example shadows the Locale
service instance by assigning the result of calling locale.get() back to the
same name; rename the result variable (e.g., localeResult or foundLocale) so it
doesn't collide with the service instance and update any subsequent references
to use the new variable name when working with the returned value from
locale.get().
| let response = RealtimeResponseEvent( | ||
| events: events, | ||
| channels: channels, | ||
| timestamp: data["timestamp"] as! String, | ||
| payload: payload | ||
| ) |
There was a problem hiding this comment.
Force-unwrap on timestamp will crash if the field is missing or has the wrong type.
Line 373 uses as! String which will cause a runtime crash if the backend omits timestamp or sends it as a non-string type. All other fields in this guard block are safely unwrapped — timestamp should be too.
🐛 Proposed fix
- let response = RealtimeResponseEvent(
- events: events,
- channels: channels,
- timestamp: data["timestamp"] as! String,
- payload: payload
- )
- subscription.callback(response)
+ if let timestamp = data["timestamp"] as? String {
+ let response = RealtimeResponseEvent(
+ events: events,
+ channels: channels,
+ timestamp: timestamp,
+ payload: payload
+ )
+ subscription.callback(response)
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let response = RealtimeResponseEvent( | |
| events: events, | |
| channels: channels, | |
| timestamp: data["timestamp"] as! String, | |
| payload: payload | |
| ) | |
| if let timestamp = data["timestamp"] as? String { | |
| let response = RealtimeResponseEvent( | |
| events: events, | |
| channels: channels, | |
| timestamp: timestamp, | |
| payload: payload | |
| ) | |
| subscription.callback(response) | |
| } |
🤖 Prompt for AI Agents
In `@Sources/Appwrite/Services/Realtime.swift` around lines 370 - 375, The code
force-unwraps data["timestamp"] when constructing RealtimeResponseEvent
(timestamp: data["timestamp"] as! String) which can crash; change to a safe
unwrap/cast (e.g., guard let timestamp = data["timestamp"] as? String else {
handle error/return } or provide a default) and use that timestamp variable when
building the RealtimeResponseEvent to match the safe unwrapping pattern used for
events/channels/payload.
This PR contains updates to the Apple SDK for version 14.1.0.