Skip to content

Commit

Permalink
just unique docIds in changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stockulus committed Sep 7, 2016
1 parent 0fd4765 commit f5caab4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
14 changes: 0 additions & 14 deletions packages/pouchdb-adapter-asyncstorage/src/asyncstorage_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ AsyncStorageCore.prototype.multiGet = function (keys, callback) {
.catch(callback)
}

AsyncStorageCore.prototype.multiGetAsObj = function (keys, callback) {
keys = keys.map(key => prepareKey(key, this))

AsyncStorage.multiGet(keys)
.then(pairs => callback(
null,
pairs.reduce((result, pair) => {
result[pair[0].slice(this._prefix.length)] = parseValue(pair[1])
return result
}, {}))
)
.catch(callback)
}

AsyncStorageCore.prototype.remove = function (key, callback) {
key = prepareKey(key, this)
AsyncStorage.removeItem(key, callback)
Expand Down
11 changes: 7 additions & 4 deletions packages/pouchdb-adapter-asyncstorage/src/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function (db, api, opts) {
const limit = ('limit' in opts && opts.limit > 0)
? opts.limit
: null
const docIds = opts.doc_ids && new Set(opts.doc_ids)
const filterDocIds = opts.doc_ids && new Set(opts.doc_ids)
const returnDocs = ('return_docs' in opts)
? opts.return_docs
: 'returnDocs' in opts
Expand All @@ -47,12 +47,14 @@ export default function (db, api, opts) {
db.storage.multiGet(toSequenceKeys(filterSeqs), (error, dataDocs) => {
if (error) return complete(error)

const filterDocs = docIds
? dataDocs.filter(doc => docIds.has(doc._id))
const filterDocs = filterDocIds
? dataDocs.filter(doc => filterDocIds.has(doc._id))
: dataDocs
if (filterDocs.length === 0) return complete(null, [])

db.storage.multiGet(filterDocs.map(data => forDocument(data._id)), (error, docs) => {
const changeDocIds = [...new Set(
filterDocs.map(data => forDocument(data._id)))]
db.storage.multiGet(changeDocIds, (error, docs) => {
if (error) return complete(error)

const dataObj = filterDocs.reduce(
Expand All @@ -70,6 +72,7 @@ export default function (db, api, opts) {
const data = dataObj[doc.id]
const change = processChange(data, doc, opts)
change.seq = doc.seq
change.rev = doc.rev

const filtered = filter(change)
if (typeof filtered === 'object') {
Expand Down

0 comments on commit f5caab4

Please sign in to comment.