Code Monkey home page Code Monkey logo

Comments (3)

alecgibson avatar alecgibson commented on August 12, 2024

We're (ab)using the op source to pass extra metadata to the server, since the source can technically be a JSON object:

doc.submitOp(op, {
  source: 'user', // nest the source if it matters to you
  options: {...}, // other stuff you want on the server
})

Of course this isn't the most semantic thing to do.

Could definitely discuss a PR that passes more information. Adding the data should be relatively simple; I deliberately added an "extra" .x field to the message, which more stuff could be added to.

The main wrinkle is dealing with op composition: if you're attaching information to a particular op, we'll probably need to force op composition to be turned off.

from sharedb.

jandrieu avatar jandrieu commented on August 12, 2024

The main wrinkle is dealing with op composition: if you're attaching information to a particular op, we'll probably need to force op composition to be turned off.

Can you say more about this?

In our case, we are passing a signed authorization token, without which the op should not occur.

So, I think you are correct. We need to treat each option as a unique, separately authorized request. We would not be able to apply the authorization from one op to another (because it contains a commitment to the particular op).

Where and how does composition happen in sharedb?

from sharedb.

alecgibson avatar alecgibson commented on August 12, 2024

We would not be able to apply the authorization from one op to another (because it contains a commitment to the particular op).

To be honest this setup sounds a little odd to me. I'm not sure I understand why you'd authenticate each op individually instead of just authenticating the connection?

Your app architecture aside, ShareDB will by default try to compose — that is, merge — ops that are submitted in quick succession (more formally, while waiting for the server acknowledgement of a currently in-flight op). That means that — by default — an op cannot be considered as a discrete unit, since it might be coalesced onto another op. This all happens on the client.

This behaviour can be manually disabled with the doc.preventCompose flag, with the obvious performance penalty of increased network traffic (although it sounds like in your particular case this is expected), and potentially increased DB storage, network and CPU load (due to having more ops stored).

The previously mentioned submitSource flag works around this by only allowing composing of ops with identical sources, which lets ops compose if the source is equal, allowing some performance gains so long as source isn't unique per-op.

from sharedb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.