Skip to content

Commit

Permalink
Do not sync judge results with firebase (#166)
Browse files Browse the repository at this point in the history
* do not sync judge results with firebase

this takes up too much space: roughly 3GB for 350k files. we should figure out a better way to do this later.

* oops

* skip sync output test
  • Loading branch information
thecodingwizard authored Dec 20, 2024
1 parent 5d21574 commit 3ba21cb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ yarn-error.log*
/playwright/.cache/
# private folder where I store firebase admin key
private
.env
.env

# ignore downloaded firebase data
/db_analysis/*.json
2 changes: 1 addition & 1 deletion e2e/runs_code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test.describe('Basic Functionality', () => {
await context2.close();
});

test('should sync output', async ({ page, browser, isMobile }) => {
test.skip('should sync output', async ({ page, browser, isMobile }) => {
const context2 = await browser.newContext();
const page2 = await context2.newPage();

Expand Down
24 changes: 12 additions & 12 deletions pages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import { useNullableUserContext } from '../src/context/UserContext';
import useUserPermission from '../src/hooks/useUserPermission';
import { SettingsModal } from '../src/components/settings/SettingsModal';
import { getSampleIndex } from '../src/components/JudgeInterface/Samples';
import useJudgeResults from '../src/hooks/useJudgeResults';
import JudgeResult from '../src/types/judge';
import useUserFileConnection from '../src/hooks/useUserFileConnection';
import useUpdateUserDashboard from '../src/hooks/useUpdateUserDashboard';
import { ConfirmOverrideModal } from '../src/components/ConfirmOverrideModal';
import Link from 'next/link';
import Head from 'next/head';
import useJudgeResults, {
JudgeResultsProvider,
} from '../src/context/JudgeResultsContext';

function EditorPage() {
const { fileData, updateFileData } = useEditorContext();
Expand All @@ -51,6 +53,7 @@ function EditorPage() {
const getMainEditorValue = useAtomValue(mainEditorValueAtom);
const getInputEditorValue = useAtomValue(inputEditorValueAtom);
const [judgeResults, setJudgeResults] = useJudgeResults();
const [isCodeRunning, setIsCodeRunning] = useState(false);

useUserFileConnection();
useUpdateUserDashboard();
Expand All @@ -74,11 +77,6 @@ function EditorPage() {

const handleRunCode = () => {
const problem = fileData.settings.problem;
const setIsRunning = (isRunning: boolean) => {
updateFileData({
isCodeRunning: isRunning,
});
};
const fetchJudge = (
code: string,
input: string,
Expand Down Expand Up @@ -113,7 +111,7 @@ function EditorPage() {
return;
}

setIsRunning(true);
setIsCodeRunning(true);
setResultAt(inputTabIndex, null);

const code = getMainEditorValue();
Expand All @@ -133,7 +131,7 @@ function EditorPage() {
);
console.error(e);
})
.finally(() => setIsRunning(false));
.finally(() => setIsCodeRunning(false));
};

const runAllSamples = async () => {
Expand All @@ -143,7 +141,7 @@ function EditorPage() {
}
const samples = problem.samples;

setIsRunning(true);
setIsCodeRunning(true);
setResultAt(1, null);

const code = getMainEditorValue();
Expand Down Expand Up @@ -206,7 +204,7 @@ function EditorPage() {
} catch (e) {
console.error(e);
}
setIsRunning(false);
setIsCodeRunning(false);
};

if (inputTab === 'input') {
Expand Down Expand Up @@ -234,7 +232,7 @@ function EditorPage() {
runButton={
<RunButton
onClick={handleRunCode}
showLoading={fileData.isCodeRunning || loading}
showLoading={isCodeRunning || loading}
disabledForViewOnly={readOnly}
/>
}
Expand Down Expand Up @@ -314,7 +312,9 @@ export default function FilePage() {
fileNotFoundUI={fileNotFoundUI}
permissionDeniedUI={permissionDeniedUI}
>
<EditorPage />
<JudgeResultsProvider>
<EditorPage />
</JudgeResultsProvider>
</EditorProvider>
<ConfirmOverrideModal />
</>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import { Output } from '../Output';
import { TabBar } from '../TabBar';
import { UserList } from '../UserList/UserList';
import Samples from '../JudgeInterface/Samples';
import useJudgeResults from '../../hooks/useJudgeResults';
import { useEditorContext } from '../../context/EditorContext';
import useUserPermission from '../../hooks/useUserPermission';
import { useUserContext } from '../../context/UserContext';
import { Sample } from '../JudgeInterface/Samples';
import useJudgeResults from '../../context/JudgeResultsContext';

export type ProblemData = {
id: number;
submittable: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import JudgeSettings from './JudgeSettings';

import SignInSettings from './SignInSettings';
import JudgeResult from '../../types/judge';
import useJudgeResults from '../../hooks/useJudgeResults';
import { EditorMode, useUserContext } from '../../context/UserContext';
import { FileSettings, useEditorContext } from '../../context/EditorContext';
import useUserPermission from '../../hooks/useUserPermission';
import firebase from 'firebase/app';
import useJudgeResults from '../../context/JudgeResultsContext';

export interface SettingsDialogProps {
isOpen: boolean;
Expand Down
4 changes: 0 additions & 4 deletions src/context/EditorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export type FileData = {
};
};
settings: FileSettings;
isCodeRunning: boolean;
state: {
judge_resuts: any; // ???
};
chat: {
[key: string]: Omit<ChatMessage, 'key'>;
};
Expand Down
30 changes: 30 additions & 0 deletions src/context/JudgeResultsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createContext, useContext, useState } from 'react';
import JudgeResult from '../types/judge';

const JudgeResultsContext = createContext<
[(JudgeResult | null)[], (newResults: (JudgeResult | null)[]) => void] | null
>(null);

export default function useJudgeResults() {
const context = useContext(JudgeResultsContext);
if (context === null) {
throw new Error(
'useJudgeResults must be used within an JudgeResultsProvider'
);
}

return context;
}

export function JudgeResultsProvider({
children,
}: {
children: React.ReactNode;
}) {
const state = useState<(JudgeResult | null)[]>([]);
return (
<JudgeResultsContext.Provider value={state}>
{children}
</JudgeResultsContext.Provider>
);
}
15 changes: 0 additions & 15 deletions src/hooks/useJudgeResults.ts

This file was deleted.

0 comments on commit 3ba21cb

Please sign in to comment.