Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-22879

Document.PageProvider operation loops indefinitely when the number of found documents is lower than the page size

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 8.10-HF12, 9.2
    • Fix Version/s: None
    • Component/s: Automation

      Description

      Contex: Using Document.PageProvider operation from JavaScript. Not tested in another context.

      To initialize/reset demo data, I use this operation to make sure I handle every documents even if there are more than the max page size of the provider. So, I am doing a do...while loop, incrementing the page number a each iteration:

      function run(input, params) {
        var currentPage, count, maxn docs;
        
        currentPage = -1;
        count = 0;
        
        do {
          currentPage += 1;
          docs = Repository.PageProvider(null, {
            'query': "SELECT * FROM File WHERE ecm:isVersion = 0 AND ecm:isProxy = 0",
            'currentPageIndex': "" + currentPage,
            'maxResults': "1000",
            'pageSize': "1000"
          });
          max = docs.length;
          Console.log("FOUND in page #" + currentPage + ": " + max);
          if(max > 0) {
            // ... handle each doc...
          }
        } while(max > 0);
      }
      

      This works very well as long as the number of documents found is greater than the pageSize: currentPageIndex is incremented and at some point, max (aka docs.length) is 0.
      But when the initial number of found documents is lower than the pageSize, we enter an infinite loop, because whatever the value of currentPage, the operation always return the same documents.

      This problem exists in LTS 2016 and 9.2

      My workaround is very, very ugly: I order by UID, save the ID of the first document, compare to next one in next loop. If they are the same => I am in the infinite loop:

      function run(input, params) {
        var currentPage, count, maxn docs;
        // wappp = "work Around PageProvider Problem"
        var wapppLastDocId = "";
        
        currentPage = -1;
        count = 0;
        
        do {
          currentPage += 1;
          docs = Repository.PageProvider(null, {
            'query': "SELECT * FROM File WHERE ecm:isVersion = 0 AND ecm:isProxy = 0 ORDER BY ecm:uuid ASC",
            'currentPageIndex': "" + currentPage,
            'maxResults': "1000",
            'pageSize': "1000"
          });
          max = docs.length;
      	Console.log("FOUND in page #" + currentPage + ": " + max);
          
          if(max > 0) {
            if(wapppLastDocId === docs[0].id) {
              max = 0;// Stop the loop
              Console.log("FORCE STOPPING THE LOOP");
            } else {
      	    wapppLastDocId = docs[0].id;
      	  }
      	}
      
          if(max > 0) {
            // ... handle each doc...
          }
        } while(max > 0);
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: