Skip to content
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

inMemory collections don't sync up removals #754

Closed
rafamel opened this issue Aug 14, 2018 · 4 comments
Closed

inMemory collections don't sync up removals #754

rafamel opened this issue Aug 14, 2018 · 4 comments

Comments

@rafamel
Copy link
Contributor

rafamel commented Aug 14, 2018

Case

Bug; inMemory collections don't sync up the removal of documents.

Issue

When a doc is removed on an inMemory, it is still present in its original collection, and also vice versa.

Info

  • Environment: Browser
  • Adapter: idb, memory
  • RxDB: 7.7.1

Code

const RxDB = require('rxdb');
RxDB.plugin(require('pouchdb-adapter-idb'));
RxDB.plugin(require('pouchdb-adapter-memory'));

async function test() {
  const db = await RxDB.create({
    name: 'testdb',
    adapter: 'idb',
    multiInstance: false
  });

  const schema = {
    version: 0,
    type: 'object',
    primaryPath: '_id',
    properties: {
      name: {
        type: 'string'
      }
    }
  };

  const collection = await db.collection({
    name: 'person',
    schema: schema,
    statics: {
      one() {
        return this.findOne();
      }
    }
  });

  // Insertion
  console.log('-'.repeat(20));
  const inMemCollection = await db.collections.person.inMemory();
  collection.insert({ name: 'hi' });
  // Wait
  await new Promise((resolve) => setTimeout(resolve, 1000));
  const inserted = await inMemCollection.findOne().exec();
  console.log(
    'Name in sync with inMemory?',
    inserted && inserted.name === 'hi'
  );

  // Removal from collection
  console.log('-'.repeat(20));
  console.log('Removing from collection');
  await collection
    .findOne()
    .exec()
    .then((x) => x.remove());
  // Wait
  await new Promise((resolve) => setTimeout(resolve, 2000));
  console.log(
    'Was removed from collection?',
    (await collection.findOne().exec()) === null
  );
  console.log(
    'Was removed from inMemory collection?',
    (await inMemCollection.findOne().exec()) === null
  );
  console.log('-'.repeat(20));
}
test();
@rafamel
Copy link
Contributor Author

rafamel commented Aug 20, 2018

This might be related to #761

@pubkey pubkey closed this as completed in 016d8bd Aug 20, 2018
@pubkey
Copy link
Owner

pubkey commented Aug 20, 2018

Ok this was a hard one :)

First problem was that as described in #761 .remove() did delete all data of the document. I always thought remove would do the same as only setting _deleted: true which was wrong, I changed it and we now use pouch.put() and only set the _deleted-flag

Also there was a bug in the query-change-detection which is fixed now.

Because pouch.bulkDocs does not work for deleting documents silently, I added a workaround which could be removed in the future when the added pouch-db-integration-test fails.

@rafamel
Copy link
Contributor Author

rafamel commented Aug 21, 2018

Amazing work, Daniel!

@hubgit
Copy link
Contributor

hubgit commented Aug 29, 2018

@pubkey If a document is deleted remotely and syncs to the local database with the data deleted (as with the old behaviour of .remove()), will the query change detector still handle it correctly?

In other words, if a deleted document used to match the query and now doesn't match the query (because it doesn't have any of the matching properties), will the query subscriber still be called?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants