fix: prevent infinite FB API pagination loop with dedup and cursor cycle detection
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Facebook Graph API can return cycling cursors causing infinite fetch loops. Added: post ID deduplication, seen-cursor detection, max 100 pages limit. Applied to both loadAllFbPosts and refreshAllFbPosts functions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
19b5c76664
commit
c324658f47
@ -905,11 +905,14 @@
|
||||
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-secondary);">Pierwsze ladowanie — pobieranie postow z Facebook API...</div>';
|
||||
|
||||
var allPosts = [];
|
||||
var seenIds = {};
|
||||
var seenCursors = {};
|
||||
var cursor = null;
|
||||
var page = 0;
|
||||
var MAX_PAGES = 100;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
while (page < MAX_PAGES) {
|
||||
page++;
|
||||
btn.textContent = 'Ladowanie... (' + allPosts.length + ' postow, strona ' + page + ')';
|
||||
|
||||
@ -926,9 +929,19 @@
|
||||
|
||||
if (!data.posts || data.posts.length === 0) break;
|
||||
|
||||
allPosts = allPosts.concat(data.posts);
|
||||
// Deduplicate by post ID
|
||||
var newPosts = data.posts.filter(function(p) {
|
||||
if (seenIds[p.id]) return false;
|
||||
seenIds[p.id] = true;
|
||||
return true;
|
||||
});
|
||||
if (newPosts.length === 0) break; // all duplicates = cycle
|
||||
allPosts = allPosts.concat(newPosts);
|
||||
|
||||
if (!data.next_cursor) break;
|
||||
// Detect cursor cycle
|
||||
if (seenCursors[data.next_cursor]) break;
|
||||
seenCursors[data.next_cursor] = true;
|
||||
cursor = data.next_cursor;
|
||||
}
|
||||
|
||||
@ -959,11 +972,14 @@
|
||||
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-secondary);">Pobieranie WSZYSTKICH postow z Facebook API...</div>';
|
||||
|
||||
var allPosts = [];
|
||||
var seenIds = {};
|
||||
var seenCursors = {};
|
||||
var cursor = null;
|
||||
var page = 0;
|
||||
var MAX_PAGES = 100;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
while (page < MAX_PAGES) {
|
||||
page++;
|
||||
btn.textContent = 'Pobieranie... (' + allPosts.length + ' postow, strona ' + page + ')';
|
||||
|
||||
@ -975,9 +991,17 @@
|
||||
|
||||
if (!data.success || !data.posts || data.posts.length === 0) break;
|
||||
|
||||
allPosts = allPosts.concat(data.posts);
|
||||
var newPosts = data.posts.filter(function(p) {
|
||||
if (seenIds[p.id]) return false;
|
||||
seenIds[p.id] = true;
|
||||
return true;
|
||||
});
|
||||
if (newPosts.length === 0) break;
|
||||
allPosts = allPosts.concat(newPosts);
|
||||
|
||||
if (!data.next_cursor) break;
|
||||
if (seenCursors[data.next_cursor]) break;
|
||||
seenCursors[data.next_cursor] = true;
|
||||
cursor = data.next_cursor;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user