-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Return Relationship Metadata for Offline Support #5556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If the client has offline persistency enabled (indicated by the X-SDK-Offline request header), the server will return the collection's relationships attributes so that while the client is offline, it knows where to store related data.
00e2f48
to
dbdd7c7
Compare
* | ||
* Returns true if the user has access to the collection | ||
*/ | ||
function getCollectionRelationships(Document $collection, bool $mode, Database $dbForProject, int $depth, array &$collections): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set a resource and inject it instead of using a global function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eldadfux, considering your comment over #5587 (comment), do you not want us to set any global functions as a resource? Some other cases where we have functions we want to re-use between endpoints are:
- create user
- createAttribute
- updateAttribute
- avatarCallback
- some graphql methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few places where we compromised on this as we didn't had any other reasonable choice. Me and @lohanidamodar are working on a longer term solution to define routes as classes. This will allow us to better reuse or extend routes logic.
} | ||
} | ||
|
||
if ($depth + 1 > Database::RELATION_MAX_DEPTH) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be clearer to use >=
instead of $depth + 1
$attributes = []; | ||
foreach ($relationshipAttributes as $attribute) { | ||
/** @var Document $attribute */ | ||
$relatedCollection = Authorization::skip(fn() => $dbForProject->getDocument('database_' . $collection->getAttribute('databaseInternalId'), $attribute->getAttribute('relatedCollection'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of skipping auth, can we utilize the permission check at the database level and check if $relatedCollection->isEmpty()
, then skip the recursion if it is? Then we can remove the manual check at the start of this function too
What does this PR do?
If the client has offline persistency enabled (indicated by the X-SDK-Offline request header), the server will return the collection's relationships attributes so that while the client is offline, it knows where to store related data.
The header will include something like:
Test Plan
TODO
Related PRs and Issues
TBD
Checklist