Skip to content

Commit

Permalink
chore: improve the polling function for indexed pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ydennisy committed May 27, 2024
1 parent f81f346 commit 8a84809
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
27 changes: 13 additions & 14 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const apiBase = config.public.apiBase;
const indexWebPages = async () => {
indexingStatusMessage.value = 'Indexing...';
const interval = startPollingIndexFeed();
const token = useSupabaseSession().value?.access_token;
// TODO: handle re-auth
if (!token) return;
Expand All @@ -46,10 +45,13 @@ const indexWebPages = async () => {
urlsCount.value = 0;
urls.value = [];
indexingStatusMessage.value = '';
clearInterval(interval);
}, 3000);
};
const formatTimeToHumanFriendly = (time: string) => {
return formatDistance(new Date(time), new Date(), { addSuffix: true });
};
const fetchIndexedPages = async () => {
const token = useSupabaseSession().value?.access_token;
// TODO: handle re-auth
Expand All @@ -70,24 +72,21 @@ const fetchIndexedPages = async () => {
}
};
const startPollingIndexFeed = () => {
const interval = setInterval(async () => {
const fetchIndexedPagesIfTabInFocus = async () => {
if (document.hasFocus()) {
await fetchIndexedPages();
}, 10000);
onUnmounted(() => {
clearInterval(interval);
});
return interval;
}
};
const formatTimeToHumanFriendly = (time: string) => {
return formatDistance(new Date(time), new Date(), { addSuffix: true });
};
let indexFeedPollingInterval: NodeJS.Timeout;
onMounted(async () => {
await fetchIndexedPages();
indexFeedPollingInterval = setInterval(fetchIndexedPagesIfTabInFocus, 10000);
});
onUnmounted(() => {
clearInterval(indexFeedPollingInterval);
});
watch(input, (newValue) => {
Expand Down
3 changes: 1 addition & 2 deletions sweep.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rules:
- "All new business logic should have corresponding unit tests."
- "Refactor large functions to be more modular."
- "Add docstrings to all functions and file headers."
- "Add documentation in complex areas of the code, which explain WHY something was implemented in a specific manner."

branch: "main"
gha_enabled: True
Expand Down

0 comments on commit 8a84809

Please sign in to comment.