reqmgr_workload_cache db and wmstats reporting wrong # events
It looks like reqmgr_workload_cache db documents sometimes report an incorrect number of TotalInputEvents, TotalInputLumis and I guess also TotalEstimatedJobs, as can be seen in this example:
https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache/pdmvserv_TRK-TP2023HGCALGS-00001_00001_v0__141113_160840_557

I've seen this in testbed already but I guess I did not manage to easily reproduce it.
Taking a quick look at the code, it seems it's coming from here:
https://github.com/dmwm/WMCore/blob/master/src/couchapps/ReqMgr/updates/totalstats.js#L17

but to be honest, I have no idea where/what "req.query.input_events" goes here.

diff --git a/src/python/WMCore/WorkQueue/WorkQueue.py b/src/python/WMCore/WorkQueue/WorkQueue.py
index d0dd02866..4a0f915fe 100644
--- a/src/python/WMCore/WorkQueue/WorkQueue.py
+++ b/src/python/WMCore/WorkQueue/WorkQueue.py
@@ -1044,11 +1044,6 @@ class WorkQueue(WorkQueueBase):
                                                                      mask=inbound['Mask'], inbound=inbound,
                                                                      continuous=continuous)
 
-                    # if global queue, then update workflow stats to request mgr couch doc
-                    # remove the "UnittestFlag" - need to create the reqmgrSvc emulator
-                    if not self.params.get('LocalQueueFlag') and not self.params.get("UnittestFlag", False):
-                        self.reqmgrSvc.updateRequestStats(inbound['WMSpec'].name(), totalStats)
-
                     # save inbound work to signal we have completed queueing
                     self.backend.insertElements(work, parent=inbound)  # if this fails, rerunning will pick up here
 
@@ -1074,6 +1069,10 @@ class WorkQueue(WorkQueueBase):
                                 rejectedWork = rejectedWork[chunkSize:]
                                 chunkProcessed = processedInputs[:chunkSize]
                                 chunkRejected = rejectedWork[:chunkSize]
+                        # if global queue, then update workflow stats to request mgr couch doc
+                        # remove the "UnittestFlag" - need to create the reqmgrSvc emulator
+                        if not self.params.get("UnittestFlag", False):
+                            self.reqmgrSvc.updateRequestStats(inbound['WMSpec'].name(), totalStats)
 
             except TERMINAL_EXCEPTIONS as ex:
                 if not continuous:
['src/python/WMCore/WorkQueue/WorkQueue.py']