cozy-pouch-link 49.0.0 → 49.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1002,6 +1002,17 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1002
1002
 
1003
1003
  if (!indexedFields) {
1004
1004
  indexedFields = (0, _mango.getIndexFields)(options);
1005
+ } else if (partialFilter) {
1006
+ // Some pouch adapters does not support partialIndex, e.g. with websql in react-native
1007
+ // Therefore, we need to force the indexing the partialIndex fields to ensure they will be
1008
+ // included in the actual index. Thanks to this, docs with missing fields will be excluded
1009
+ // from the index.
1010
+ // Note the $exists: false case should be handled in-memory.
1011
+ indexedFields = Array.from(new Set([].concat((0, _toConsumableArray2.default)(indexedFields), (0, _toConsumableArray2.default)(Object.keys(partialFilter))))); // FIXME: should properly handle n-level attributes
1012
+
1013
+ indexedFields = indexedFields.filter(function (field) {
1014
+ return field !== '$and' && field !== '$or';
1015
+ });
1005
1016
  }
1006
1017
 
1007
1018
  indexName = (0, _mango.getIndexNameFromFields)(indexedFields, partialFilter);
@@ -608,9 +608,10 @@ describe('CozyPouchLink', () => {
608
608
  expect(spy).toHaveBeenCalled()
609
609
  expect(spy).toHaveBeenCalledWith({
610
610
  index: {
611
- ddoc: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
612
- fields: ['myIndex'],
613
- indexName: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
611
+ ddoc: 'by_myIndex_and_SOME_FIELD_filter_(SOME_FIELD_$exists_true)',
612
+ fields: ['myIndex', 'SOME_FIELD'],
613
+ indexName:
614
+ 'by_myIndex_and_SOME_FIELD_filter_(SOME_FIELD_$exists_true)',
614
615
  partial_filter_selector: {
615
616
  SOME_FIELD: {
616
617
  $exists: true
@@ -620,6 +621,38 @@ describe('CozyPouchLink', () => {
620
621
  })
621
622
  })
622
623
 
624
+ it('should exclude $and and $or operators from fields with partialIndex', async () => {
625
+ spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
626
+ await setup()
627
+ await link.ensureIndex(TODO_DOCTYPE, {
628
+ indexedFields: ['myIndex'],
629
+ partialFilter: {
630
+ $and: [
631
+ { SOME_FIELD: { $exists: true } },
632
+ { SOME_FIELD: { $gt: null } }
633
+ ],
634
+ $or: [{ SOME_FIELD: { $eq: '1' } }, { SOME_FIELD: { $eq: '2' } }]
635
+ }
636
+ })
637
+ expect(spy).toHaveBeenCalled()
638
+ expect(spy).toHaveBeenCalledWith({
639
+ index: {
640
+ ddoc:
641
+ 'by_myIndex_filter_((SOME_FIELD_$exists_true)_$and_(SOME_FIELD_$gt_null))_and_((SOME_FIELD_$eq_1)_$or_(SOME_FIELD_$eq_2))',
642
+ fields: ['myIndex'],
643
+ indexName:
644
+ 'by_myIndex_filter_((SOME_FIELD_$exists_true)_$and_(SOME_FIELD_$gt_null))_and_((SOME_FIELD_$eq_1)_$or_(SOME_FIELD_$eq_2))',
645
+ partial_filter_selector: {
646
+ $and: [
647
+ { SOME_FIELD: { $exists: true } },
648
+ { SOME_FIELD: { $gt: null } }
649
+ ],
650
+ $or: [{ SOME_FIELD: { $eq: '1' } }, { SOME_FIELD: { $eq: '2' } }]
651
+ }
652
+ }
653
+ })
654
+ })
655
+
623
656
  it('uses the specified index', async () => {
624
657
  let spyIndex = jest
625
658
  .spyOn(CozyPouchLink.prototype, 'ensureIndex')
@@ -35,7 +35,10 @@ var _replicateOnce3 = require("./replicateOnce");
35
35
 
36
36
  var _utils = require("./utils");
37
37
 
38
- var DEFAULT_DELAY = 30 * 1000;
38
+ var DEFAULT_DELAY = 30 * 1000; // See view_update_changes_batch_size in https://pouchdb.com/api.html#create_database
39
+ // PouchDB default is 50, which badly hurt performances for large databases
40
+
41
+ var DEFAULT_VIEW_UPDATE_BATCH = 1000;
39
42
  /**
40
43
  * @param {import('cozy-client/types/types').Query} query The query definition whose name we're getting
41
44
  *
@@ -79,6 +82,11 @@ var PouchManager = /*#__PURE__*/function () {
79
82
  case 0:
80
83
  pouchPlugins = (0, _get.default)(this.options, 'pouch.plugins', []);
81
84
  pouchOptions = (0, _get.default)(this.options, 'pouch.options', {});
85
+
86
+ if (!pouchOptions.view_update_changes_batch_size) {
87
+ pouchOptions.view_update_changes_batch_size = DEFAULT_VIEW_UPDATE_BATCH;
88
+ }
89
+
82
90
  (0, _forEach.default)(pouchPlugins, function (plugin) {
83
91
  return _this.PouchDB.plugin(plugin);
84
92
  });
@@ -87,15 +95,15 @@ var PouchManager = /*#__PURE__*/function () {
87
95
  }));
88
96
  /** @type {Record<string, import('./types').SyncInfo>} - Stores synchronization info per doctype */
89
97
 
90
- _context.next = 6;
98
+ _context.next = 7;
91
99
  return this.storage.getPersistedSyncedDoctypes();
92
100
 
93
- case 6:
101
+ case 7:
94
102
  this.syncedDoctypes = _context.sent;
95
- _context.next = 9;
103
+ _context.next = 10;
96
104
  return this.storage.getPersistedWarmedUpQueries();
97
105
 
98
- case 9:
106
+ case 10:
99
107
  this.warmedUpQueries = _context.sent;
100
108
  this.getReplicationURL = this.options.getReplicationURL;
101
109
  this.doctypesReplicationOptions = this.options.doctypesReplicationOptions || {};
@@ -111,7 +119,7 @@ var PouchManager = /*#__PURE__*/function () {
111
119
 
112
120
  this.replications = undefined;
113
121
 
114
- case 19:
122
+ case 20:
115
123
  case "end":
116
124
  return _context.stop();
117
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "49.0.0",
3
+ "version": "49.1.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/cozy/cozy-client.git"
14
14
  },
15
15
  "dependencies": {
16
- "cozy-client": "^49.0.0",
16
+ "cozy-client": "^49.1.1",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -39,5 +39,5 @@
39
39
  "typecheck": "tsc -p tsconfig.json"
40
40
  },
41
41
  "sideEffects": false,
42
- "gitHead": "ddf825045c0640e383b7cf89f9937ef7d44e501d"
42
+ "gitHead": "1743f0008b06d89bacda019231dd2292748c68d5"
43
43
  }