nodebb-plugin-ezoic-infinite 1.5.65 → 1.5.66

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +26 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.5.65",
3
+ "version": "1.5.66",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -82,6 +82,10 @@
82
82
  io: null,
83
83
  runQueued: false,
84
84
 
85
+ needsMoreRun: false,
86
+ moreRunBurst: 0,
87
+ moreRunLast: 0,
88
+
85
89
  // preloading budget
86
90
  inflight: 0,
87
91
  pending: [],
@@ -716,8 +720,10 @@ function startShow(id) {
716
720
  let inserted = 0;
717
721
  const maxInserts = MAX_INSERTS_PER_RUN + (isBoosted() ? 1 : 0);
718
722
 
723
+ let hitLimit = false;
724
+
719
725
  for (const afterPos of targets) {
720
- if (inserted >= maxInserts) break;
726
+ if (inserted >= maxInserts) { hitLimit = true; break; }
721
727
 
722
728
  const el = items[afterPos - 1];
723
729
  if (!el || !el.isConnected) continue;
@@ -749,6 +755,11 @@ function startShow(id) {
749
755
  inserted += 1;
750
756
  }
751
757
 
758
+ if (hitLimit) {
759
+ // We intentionally cap per run for smoothness. If we hit the cap, queue another pass.
760
+ state.needsMoreRun = true;
761
+ }
762
+
752
763
  return inserted;
753
764
  }
754
765
 
@@ -760,6 +771,8 @@ function startShow(id) {
760
771
 
761
772
  initPools(cfg);
762
773
 
774
+ state.needsMoreRun = false;
775
+
763
776
  const kind = getKind();
764
777
  let items = [];
765
778
  let allIds = [];
@@ -866,6 +879,18 @@ function startShow(id) {
866
879
  declusterWraps('ezoic-ad-categories');
867
880
  }
868
881
  }
882
+ // If we hit the per-run insertion cap, schedule another pass soon.
883
+ // Guard against infinite loops when nothing more can be inserted (e.g. no ids / adjacency everywhere).
884
+ if (state.needsMoreRun) {
885
+ const now = Date.now();
886
+ if (now - state.moreRunLast > 800) state.moreRunBurst = 0;
887
+ state.moreRunLast = now;
888
+ state.moreRunBurst += 1;
889
+ if (state.moreRunBurst <= 8) {
890
+ setTimeout(scheduleRun, 60);
891
+ }
892
+ }
893
+
869
894
  }
870
895
 
871
896
  function scheduleRun() {