working on concurrency bug

This commit is contained in:
2024-11-18 13:01:27 -07:00
parent d689b4b684
commit cdd71a672f
5 changed files with 25 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ export default function EditLecture({ lectureDay }: { lectureDay: string }) {
} else { } else {
if (lecture) { if (lecture) {
console.log( console.log(
"client not authoritative, updating client with server data" "client not authoritative, updating client with server lecture"
); );
textUpdate(lectureToString(lecture), true); textUpdate(lectureToString(lecture), true);
} else { } else {

View File

@@ -35,8 +35,14 @@ export default function EditAssignment({
useAssignmentQuery(moduleName, assignmentName); useAssignmentQuery(moduleName, assignmentName);
const updateAssignment = useUpdateAssignmentMutation(); const updateAssignment = useUpdateAssignmentMutation();
const { clientIsAuthoritative, text, textUpdate, monacoKey } = const {
useAuthoritativeUpdates({ clientIsAuthoritative,
text,
textUpdate,
monacoKey,
serverUpdatedAt,
clientDataUpdatedAt,
} = useAuthoritativeUpdates({
serverUpdatedAt: serverDataUpdatedAt, serverUpdatedAt: serverDataUpdatedAt,
startingText: localAssignmentMarkdown.toMarkdown(assignment), startingText: localAssignmentMarkdown.toMarkdown(assignment),
}); });
@@ -79,7 +85,11 @@ export default function EditAssignment({
}); });
} else { } else {
console.log( console.log(
"client not authoritative, updating client with server data" "client not authoritative, updating client with server assignment",
"client updated",
clientDataUpdatedAt,
"server updated",
serverUpdatedAt
); );
textUpdate(localAssignmentMarkdown.toMarkdown(assignment), true); textUpdate(localAssignmentMarkdown.toMarkdown(assignment), true);
} }
@@ -96,10 +106,12 @@ export default function EditAssignment({
}, [ }, [
assignment, assignment,
assignmentName, assignmentName,
clientDataUpdatedAt,
clientIsAuthoritative, clientIsAuthoritative,
courseName, courseName,
moduleName, moduleName,
router, router,
serverUpdatedAt,
text, text,
textUpdate, textUpdate,
updateAssignment, updateAssignment,

View File

@@ -72,7 +72,7 @@ export default function EditPage({
}); });
} else { } else {
console.log( console.log(
"client not authoritative, updating client with server data" "client not authoritative, updating client with server page"
); );
textUpdate(localPageMarkdownUtils.toMarkdown(page), true); textUpdate(localPageMarkdownUtils.toMarkdown(page), true);
} }

View File

@@ -111,7 +111,7 @@ export default function EditQuiz({
}); });
} else { } else {
console.log( console.log(
"client not authoritative, updating client with server data" "client not authoritative, updating client with server quiz"
); );
textUpdate(quizMarkdownUtils.toMarkdown(quiz), true); textUpdate(quizMarkdownUtils.toMarkdown(quiz), true);
} }

View File

@@ -13,11 +13,6 @@ export function useAuthoritativeUpdates({
useState(serverUpdatedAt); useState(serverUpdatedAt);
const [updateMonacoKey, setUpdateMonacoKey] = useState(1); const [updateMonacoKey, setUpdateMonacoKey] = useState(1);
const clientIsAuthoritative = useMemo(
() => serverUpdatedAt <= clientDataUpdatedAt,
[clientDataUpdatedAt, serverUpdatedAt]
);
// console.log("client is authoritative", clientIsAuthoritative); // console.log("client is authoritative", clientIsAuthoritative);
const textUpdate = useCallback((t: string, updateMonaco: boolean = false) => { const textUpdate = useCallback((t: string, updateMonaco: boolean = false) => {
setText(t); setText(t);
@@ -27,11 +22,13 @@ export function useAuthoritativeUpdates({
return useMemo( return useMemo(
() => ({ () => ({
clientIsAuthoritative, clientIsAuthoritative: serverUpdatedAt <= clientDataUpdatedAt,
serverUpdatedAt,
clientDataUpdatedAt,
textUpdate, textUpdate,
text, text,
monacoKey: updateMonacoKey, monacoKey: updateMonacoKey,
}), }),
[clientIsAuthoritative, text, textUpdate, updateMonacoKey] [clientDataUpdatedAt, serverUpdatedAt, text, textUpdate, updateMonacoKey]
); );
} }