-
Notifications
You must be signed in to change notification settings - Fork 450
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
Allow options to be passed for fetch
and getOps
#215
Conversation
Personally I'd prefer not to merge this PR because Perhaps we could consider adding extra functions to the public server API, however, I'd like to know first some specific use cases where such functions would be necessary. |
@gkubisa thanks for getting back to me. I agree that it's not a documented API, so maybe it would be nice to expose it properly? We're currently trying to regenerate documents using the |
@alecgibson That's a really cool feature! It would be great to document and expose all parts of the ShareDB API required to implement that. Perhaps this PR can add that documentation, and then we can consider it a "public" API? |
Okay, so given that If people are happy to already consider it public, I'm happy to document it (although having only dabbled in the codebase, I'm still unclear on what things like If you're worried about the maintenance burden of supporting particular features, I'm also happy to expose a limited subset of options that can be provided (although I think I've only seen |
Ok, so as I understand, you need a document at a specific version and the specific version you need is determined based on the operation timestamp. Getting Document at a Specific VersionThe rich-text type is not invertible, so you'd need the initial snapshot, which ShareDB does not store. Unless you know the initial snapshot for each document (eg it's always empty or stored outside ShareDB), you can't regenerate past snapshots. If your type were invertible, you could start with the latest snapshot and work your way backwards until you reach the snapshot you need. ShareDB could be extended to support retrieving snapshots at specific versions for any type. In my opinion that functionality should be exposed through the client API, not the server API. In order to make it work for any type, not only invertible types, ShareDB would need to also store an initial snapshot for each document. The clients could then request a specific snapshot - possibly by specifying a version number as a parameter to the I'll also need this functionality, so I might implement it at some point, unless you or someone else wants to do it. Getting a Version/Snapshot by a TimestampI'm not sure how to expose it in the public API in a nice way... the timestamps seem to be an implementation detail to me. Do you have any ideas? There's also always the option of querying the database directly. |
Unless I'm missing something, I always get the We then apply all ops on top of that creation op, because - as you say -
Depending on how nice you want to be to people, you could expose it as you suggested above, through the
I have thought about it (especially because |
@alecgibson , thanks for a great reply. :-)
You're right, sorry I missed that.
Sounds good to me. |
@gkubisa okay, so what we're saying is you'd prefer a PR that actually implements the version-fetching, rather than exposing this Where would be the best place to discuss planning and implementation? Should I raise an issue to discuss further? |
Yes, I'd prefer a client API for version-fetching because it'd be much easier to use - just 1 param for Another advantage of the simple client API is that it could be optimized internally, without affecting client code. For example:
I don't think we need any of those optimizations for the initial implementation but it's good to know that they can be implemented in a way that's transparent to the client code.
Yes, I completely agree. I'd say that the reason is the lack of time needed to expose that functionality rather than anything else.
Yes, I think a new Issue would be great. |
I'm closing this and moving discussion to this issue: #218 |
After a bit more work with ShareDB, I think that this change is a valid one to make. Even if we ignore the desire to regenerate snapshots, since being told to store information in op metadata, we now have a legitimate need to access this metadata, and I think it's a fair thing to ask for. Given that |
If we're going to add options to the backend methods, I'd recommend we do this consistently and add this to all the methods that call into DB methods. Otherwise, no major objections. Seems useful |
@nateps I've had a look, and I've reminded myself that we do indeed want this functionality - we sometimes want to fetch some ops and check the metadata on them (very helpful for displaying document history). I've had a look at just bypassing I'm all for also adding options to other methods, but I think we potentially need to discuss if we should add it to all the methods. For example, we could allow options on |
Let's be explicit and in each case nest the options for the db menthod within an appropriate property. We could use |
I've added options to |
The database adapters allow an `options` object to be passed through to them for enabling the return of metadata with a snapshot or ops. Consumers could query the database directly, or even use the database adapters, but this may give inconsistent results when comparing ops with those fetched through `getOps`. For example, the Mongo adapter makes sure that a valid set of ops with unique versions are returned, which may not be the case when querying the database directly. Fetching ops and snapshots through `Backend` methods also ensures that we call the appropriate "sanitize" methods, and trigger the corresponding middleware. However, we don't expose this on `Backend.getOps` or `Backend.fetch`. This change adds an optional `options` argument to these methods, which can then be used to ask for metadata. Note that an options argument has been added to `Backend.subscribe`, but using it will return an error. This is to keep the signature consistent with `fetch` and `getOps`. However, the implementation is beyond the scope of this change, because we'd need to add some way to configure `SubmitRequest.commit` to optionally pass metadata to the appropriate clients, who provided that given option on `subscribe`.
Backend.getOps
fetch
and getOps
As discussed, I've added the |
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.
LGTM, I'd recommend adding documentation of the Backend class and these methods to the readme.
Thanks!
The database adapters allow an
options
object to be passed through tothem for enabling the return of metadata with a snapshot or ops.
Consumers could query the database directly, or even use the database
adapters, but this may give inconsistent results when comparing ops with
those fetched through
getOps
. For example, the Mongo adapter makessure that a valid set of ops with unique versions are returned, which
may not be the case when querying the database directly. Fetching ops
and snapshots through
Backend
methods also ensures that we call theappropriate "sanitize" methods, and trigger the corresponding
middleware.
However, we don't expose this on
Backend.getOps
orBackend.fetch
.This change adds an optional
options
argument to these methods, whichcan then be used to ask for metadata.
Note that an options argument has been added to
Backend.subscribe
, butusing it will return an error. This is to keep the signature consistent
with
fetch
andgetOps
. However, the implementation is beyond thescope of this change, because we'd need to add some way to configure
SubmitRequest.commit
to optionally pass metadata to the appropriateclients, who provided that given option on
subscribe
.