mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: update revalidation settings for course metadata to improve caching efficiency
This commit is contained in:
parent
57df92ab2c
commit
f712d68e28
5 changed files with 12 additions and 6 deletions
|
|
@ -24,7 +24,7 @@ export async function generateMetadata(props: MetadataProps): Promise<Metadata>
|
||||||
// Get Org context information
|
// Get Org context information
|
||||||
const course_meta = await getCourseMetadata(
|
const course_meta = await getCourseMetadata(
|
||||||
params.courseid,
|
params.courseid,
|
||||||
{ revalidate: 0, tags: ['courses'] },
|
{ revalidate: 30, tags: ['courses'] },
|
||||||
access_token ? access_token : null
|
access_token ? access_token : null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ const EditActivity = async (params: any) => {
|
||||||
const courseid = (await params.params).courseid
|
const courseid = (await params.params).courseid
|
||||||
const courseInfo = await getCourseMetadata(
|
const courseInfo = await getCourseMetadata(
|
||||||
courseid,
|
courseid,
|
||||||
{ revalidate: 0, tags: ['courses'] },
|
{ revalidate: 30, tags: ['courses'] },
|
||||||
access_token ? access_token : null
|
access_token ? access_token : null
|
||||||
)
|
)
|
||||||
const activity = await getActivityWithAuthHeader(
|
const activity = await getActivityWithAuthHeader(
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import ActivityBreadcrumbs from '@components/Pages/Activity/ActivityBreadcrumbs'
|
||||||
import MiniInfoTooltip from '@components/Objects/MiniInfoTooltip'
|
import MiniInfoTooltip from '@components/Objects/MiniInfoTooltip'
|
||||||
import GeneralWrapperStyled from '@components/Objects/StyledElements/Wrappers/GeneralWrapper'
|
import GeneralWrapperStyled from '@components/Objects/StyledElements/Wrappers/GeneralWrapper'
|
||||||
import ActivityIndicators from '@components/Pages/Courses/ActivityIndicators'
|
import ActivityIndicators from '@components/Pages/Courses/ActivityIndicators'
|
||||||
|
import { revalidateTags } from '@services/utils/ts/requests'
|
||||||
|
|
||||||
// Lazy load heavy components
|
// Lazy load heavy components
|
||||||
const Canva = lazy(() => import('@components/Objects/Activities/DynamicCanva/DynamicCanva'))
|
const Canva = lazy(() => import('@components/Objects/Activities/DynamicCanva/DynamicCanva'))
|
||||||
|
|
@ -736,6 +737,9 @@ export function MarkStatus(props: {
|
||||||
try {
|
try {
|
||||||
const willCompleteAll = areAllActivitiesCompleted();
|
const willCompleteAll = areAllActivitiesCompleted();
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
// refresh the page after marking the activity as complete
|
||||||
|
await revalidateTags(['courses'], props.orgslug);
|
||||||
|
router.refresh();
|
||||||
await markActivityAsComplete(
|
await markActivityAsComplete(
|
||||||
props.orgslug,
|
props.orgslug,
|
||||||
props.course.course_uuid,
|
props.course.course_uuid,
|
||||||
|
|
@ -768,7 +772,7 @@ export function MarkStatus(props: {
|
||||||
props.activity.activity_uuid,
|
props.activity.activity_uuid,
|
||||||
session.data?.tokens?.access_token
|
session.data?.tokens?.access_token
|
||||||
);
|
);
|
||||||
|
await revalidateTags(['courses'], props.orgslug);
|
||||||
await mutate(`${getAPIUrl()}courses/${props.course.course_uuid}/meta`);
|
await mutate(`${getAPIUrl()}courses/${props.course.course_uuid}/meta`);
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type Session = {
|
||||||
async function fetchCourseMetadata(courseuuid: string, access_token: string | null | undefined) {
|
async function fetchCourseMetadata(courseuuid: string, access_token: string | null | undefined) {
|
||||||
return await getCourseMetadata(
|
return await getCourseMetadata(
|
||||||
courseuuid,
|
courseuuid,
|
||||||
{ revalidate: 0, tags: ['courses'] },
|
{ revalidate: 30, tags: ['courses'] },
|
||||||
access_token || null
|
access_token || null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export async function generateMetadata(props: MetadataProps): Promise<Metadata>
|
||||||
})
|
})
|
||||||
const course_meta = await getCourseMetadata(
|
const course_meta = await getCourseMetadata(
|
||||||
params.courseuuid,
|
params.courseuuid,
|
||||||
{ revalidate: 0, tags: ['courses'] },
|
{ revalidate: 30, tags: ['courses'] },
|
||||||
access_token ? access_token : null
|
access_token ? access_token : null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ const CoursePage = async (params: any) => {
|
||||||
// Fetch course metadata once
|
// Fetch course metadata once
|
||||||
const course_meta = await getCourseMetadata(
|
const course_meta = await getCourseMetadata(
|
||||||
params.params.courseuuid,
|
params.params.courseuuid,
|
||||||
{ revalidate: 0, tags: ['courses'] },
|
{ revalidate: 30, tags: ['courses'] },
|
||||||
access_token ? access_token : null
|
access_token ? access_token : null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@ const CourseActionsMobile = ({ courseuuid, orgslug, course }: CourseActionsMobil
|
||||||
|
|
||||||
if (firstActivity) {
|
if (firstActivity) {
|
||||||
// Redirect to the first activity
|
// Redirect to the first activity
|
||||||
|
await revalidateTags(['activities'], orgslug)
|
||||||
router.push(
|
router.push(
|
||||||
getUriWithOrg(orgslug, '') +
|
getUriWithOrg(orgslug, '') +
|
||||||
`/course/${courseuuid}/activity/${firstActivity.activity_uuid.replace('activity_', '')}`
|
`/course/${courseuuid}/activity/${firstActivity.activity_uuid.replace('activity_', '')}`
|
||||||
|
|
@ -209,6 +210,7 @@ const CourseActionsMobile = ({ courseuuid, orgslug, course }: CourseActionsMobil
|
||||||
console.error('Failed to perform course action:', error)
|
console.error('Failed to perform course action:', error)
|
||||||
} finally {
|
} finally {
|
||||||
setIsActionLoading(false)
|
setIsActionLoading(false)
|
||||||
|
await revalidateTags(['courses'], orgslug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue