Skip to content

Commit

Permalink
feat: request health api for session keep-alive (halo-dev#4949)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/area console
/kind improvement
/milestone 2.11.0

#### What this PR does / why we need it:

在 Console 和 UC 轮询 /actuator/health 接口保持登录会话,目前是 5min 请求一次。

#### Which issue(s) this PR fixes:

Fixes halo-dev#4947 

#### Does this PR introduce a user-facing change?

```release-note
优化 Console 的登录会话保活机制。
```
  • Loading branch information
ruibaby authored Nov 30, 2023
1 parent 6e70d2e commit 8f83df4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { usePageUpdateMutate } from "./composables/use-page-update-mutate";
import { useAutoSaveContent } from "@console/composables/use-auto-save-content";
import { useContentSnapshot } from "@console/composables/use-content-snapshot";
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
const router = useRouter();
const { t } = useI18n();
Expand Down Expand Up @@ -373,6 +374,9 @@ const handlePreview = async () => {
useSaveKeybinding(handleSave);
// Keep session alive
useSessionKeepAlive();
// Upload image
async function handleUploadImage(file: File) {
if (!isUpdateMode.value) {
Expand Down
4 changes: 4 additions & 0 deletions console/console-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { contentAnnotations } from "@/constants/annotations";
import { useAutoSaveContent } from "@console/composables/use-auto-save-content";
import { useContentSnapshot } from "@console/composables/use-content-snapshot";
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
const router = useRouter();
const { t } = useI18n();
Expand Down Expand Up @@ -398,6 +399,9 @@ const handlePreview = async () => {
useSaveKeybinding(handleSave);
// Keep session alive
useSessionKeepAlive();
// Upload image
async function handleUploadImage(file: File) {
if (!isUpdateMode.value) {
Expand Down
15 changes: 15 additions & 0 deletions console/src/composables/use-session-keep-alive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useUserStore } from "@/stores/user";
import { useQuery } from "@tanstack/vue-query";
import { computed } from "vue";

export function useSessionKeepAlive() {
const { isAnonymous } = useUserStore();

useQuery({
queryKey: ["health", "keep-session-alive"],
queryFn: () => fetch("/actuator/health"),
refetchInterval: 1000 * 60 * 5, // 5 minutes
refetchOnWindowFocus: true,
enabled: computed(() => !isAnonymous),
});
}
4 changes: 4 additions & 0 deletions console/uc-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import PostSettingEditModal from "./components/PostSettingEditModal.vue";
import HasPermission from "@/components/permission/HasPermission.vue";
import { provide } from "vue";
import type { ComputedRef } from "vue";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
const router = useRouter();
const { t } = useI18n();
Expand Down Expand Up @@ -350,6 +351,9 @@ async function handleUploadImage(file: File) {
});
return data;
}
// Keep session alive
useSessionKeepAlive();
</script>

<template>
Expand Down

0 comments on commit 8f83df4

Please sign in to comment.