This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 00f840636 adapter-idb: count docs with attachments in total_rows
00f840636 is described below

commit 00f840636ca6f8eb817cef2632d13ad85180005d
Author: alxndrsn <alxndrsn>
AuthorDate: Thu Nov 20 05:02:43 2025 +0000

    adapter-idb: count docs with attachments in total_rows
    
    Docs initially inserted with attachments were not added to the metaDocs 
docCount.
---
 .../node_modules/pouchdb-adapter-idb/src/bulkDocs.js   | 16 ++++++++--------
 tests/integration/test.basics.js                       | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js 
b/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js
index a9dfdf2db..b161f3078 100644
--- a/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js
+++ b/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js
@@ -236,20 +236,20 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, 
callback) {
     var hasAttachments = doc._attachments &&
       Object.keys(doc._attachments).length;
     if (hasAttachments) {
-      return writeAttachments(docInfo, winningRev, winningRevIsDeleted,
+      return writeAttachments(docInfo, delta, winningRev, winningRevIsDeleted,
         isUpdate, resultsIdx, callback);
     }
 
-    docCountDelta += delta;
-    updateDocCountIfReady();
-
-    finishDoc(docInfo, winningRev, winningRevIsDeleted,
+    finishDoc(docInfo, delta, winningRev, winningRevIsDeleted,
       isUpdate, resultsIdx, callback);
   }
 
-  function finishDoc(docInfo, winningRev, winningRevIsDeleted,
+  function finishDoc(docInfo, delta, winningRev, winningRevIsDeleted,
                      isUpdate, resultsIdx, callback) {
 
+    docCountDelta += delta;
+    updateDocCountIfReady();
+
     var doc = docInfo.data;
     var metadata = docInfo.metadata;
 
@@ -305,7 +305,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) 
{
     putReq.onerror = afterPutDocError;
   }
 
-  function writeAttachments(docInfo, winningRev, winningRevIsDeleted,
+  function writeAttachments(docInfo, delta, winningRev, winningRevIsDeleted,
                             isUpdate, resultsIdx, callback) {
 
 
@@ -316,7 +316,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) 
{
 
     function collectResults() {
       if (numDone === attachments.length) {
-        finishDoc(docInfo, winningRev, winningRevIsDeleted,
+        finishDoc(docInfo, delta, winningRev, winningRevIsDeleted,
           isUpdate, resultsIdx, callback);
       }
     }
diff --git a/tests/integration/test.basics.js b/tests/integration/test.basics.js
index 7737dd79f..ea64c9b7b 100644
--- a/tests/integration/test.basics.js
+++ b/tests/integration/test.basics.js
@@ -1339,5 +1339,23 @@ adapters.forEach(function (adapter) {
         }).should.throw(Error, 'Invalid plugin: got "pouchdb-adapter-memory", 
expected an object or a function');
       });
     }
+
+    it('#9094 should update total_rows when doc is put with an attachment', 
async () => {
+      // given
+      const db = new PouchDB(dbs.name);
+      await db.put({ _id:'foo', _attachments:{ 'simple.txt':{ 
content_type:'text/plain', data:'helo' } } });
+      const { rows, total_rows } = await db.allDocs();
+      rows.length.should.equal(1);
+      total_rows.should.equal(1);
+    });
+
+    it('#9094 should update total_rows when doc is posted with an attachment', 
async () => {
+      // given
+      const db = new PouchDB(dbs.name);
+      await db.post({ _attachments:{ 'simple.txt':{ content_type:'text/plain', 
data:'helo' } } });
+      const { rows, total_rows } = await db.allDocs();
+      rows.length.should.equal(1);
+      total_rows.should.equal(1);
+    });
   });
 });

Reply via email to