Refactor API permissions and throttling: Updated default permission classes to enforce authentication and tenant access. Introduced new permission for system accounts and developers. Enhanced throttling rates for various operations to reduce false 429 errors. Improved API key loading logic to prioritize account-specific settings, with fallbacks to system accounts and Django settings. Updated integration views and sidebar to reflect new permission structure.

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-07 17:23:42 +00:00
parent 3cbed65601
commit 65fea95d33
15 changed files with 374 additions and 71 deletions

View File

@@ -432,18 +432,23 @@ export default function Home() {
const fetchAppInsights = async () => {
try {
setLoading(true);
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
// Determine site_id based on filter
const siteId = siteFilter === 'all' ? undefined : siteFilter;
const [keywordsRes, clustersRes, ideasRes, tasksRes, contentRes, imagesRes] = await Promise.all([
fetchKeywords({ page_size: 1, site_id: siteId }),
fetchClusters({ page_size: 1, site_id: siteId }),
fetchContentIdeas({ page_size: 1, site_id: siteId }),
fetchTasks({ page_size: 1, site_id: siteId }),
fetchContent({ page_size: 1, site_id: siteId }),
fetchContentImages({ page_size: 1, site_id: siteId })
]);
// Fetch sequentially with small delays to avoid burst throttling
const keywordsRes = await fetchKeywords({ page_size: 1, site_id: siteId });
await delay(120);
const clustersRes = await fetchClusters({ page_size: 1, site_id: siteId });
await delay(120);
const ideasRes = await fetchContentIdeas({ page_size: 1, site_id: siteId });
await delay(120);
const tasksRes = await fetchTasks({ page_size: 1, site_id: siteId });
await delay(120);
const contentRes = await fetchContent({ page_size: 1, site_id: siteId });
await delay(120);
const imagesRes = await fetchContentImages({ page_size: 1, site_id: siteId });
const totalKeywords = keywordsRes.count || 0;
const totalClusters = clustersRes.count || 0;
@@ -500,8 +505,15 @@ export default function Home() {
setLastUpdated(new Date());
} catch (error: any) {
console.error('Error fetching insights:', error);
toast.error(`Failed to load insights: ${error.message}`);
if (error?.status === 429) {
// Back off and retry once after a short delay
setTimeout(() => {
fetchAppInsights();
}, 2000);
} else {
console.error('Error fetching insights:', error);
toast.error(`Failed to load insights: ${error.message}`);
}
} finally {
setLoading(false);
}