Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export async function createContext(
) {
let session = null;

// Extract request from opts if available (priority to explicit req)
const req = opts?.req || opts?.req;
// Extract request from opts if available
const req = opts?.req;

// Only attempt auth if database is available
if (db) {
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/middleware/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export class CacheService {
}

/**
* Delete all keys matching a pattern
* Delete all keys matching a pattern (glob-style with * wildcard)
*/
deletePattern(pattern: string): number {
let count = 0;
const regex = new RegExp(pattern.replace(/\*/g, '.*'));
// Escape regex special chars, then convert * to .*
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`^${escaped.replace(/\*/g, '.*')}$`);

for (const key of this.cache.keys()) {
if (regex.test(key)) {
Expand Down
14 changes: 12 additions & 2 deletions packages/api/src/routers/judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import {
import { eq, and, asc, desc, sql } from "drizzle-orm";
import { CacheKeys } from "../middleware/cache";

// Fisher-Yates shuffle for unbiased randomization
function shuffleArray<T>(array: T[]): T[] {
const result = [...array];
for (let i = result.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}

// Middleware to check if user is a judge
const isJudge = protectedProcedure.use(async ({ ctx, next }) => {
const judge = await ctx.db!.query.judges.findFirst({
Expand Down Expand Up @@ -631,9 +641,9 @@ export const judgeRouter = createTRPCRouter({
orderBy: [asc(judgingProjects.tableNumber)],
});

// Optionally shuffle
// Optionally shuffle using Fisher-Yates algorithm
if (input.shuffle) {
projects = projects.sort(() => Math.random() - 0.5);
projects = shuffleArray(projects);
}

// Create queue entries
Expand Down
6 changes: 2 additions & 4 deletions sites/mainweb/components/Background/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";

interface BackgroundProps extends React.HTMLAttributes<HTMLDivElement> {}

const Background: React.FC<BackgroundProps> = (props) => {
export default function Background(props: BackgroundProps) {
return (
<div
{...props}
Expand All @@ -19,6 +19,4 @@ const Background: React.FC<BackgroundProps> = (props) => {
<div className="absolute w-full h-full"></div>
</div>
);
};

export default Background;
}
2 changes: 1 addition & 1 deletion sites/mainweb/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nextJsConfig } from "@query/eslint-config/next-js";
import nextJsConfig from "@query/eslint-config/next-js";

/** @type {import("eslint").Linter.Config} */
export default nextJsConfig;
2 changes: 1 addition & 1 deletion tooling/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"exports": {
"./base": "./base.js",
"./nextjs": "./nextjs.js",
"./next-js": "./next.js",
"./react": "./react.js"
},
"scripts": {
Expand Down
Loading