📈 Added analytics on time spent running PoW-stuff

This commit is contained in:
Mawoka
2022-06-23 21:27:03 +02:00
parent 6e04dfc60d
commit 9756aa45af
3 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ async def upload_image(edit_id: str, pow_data: str, file: UploadFile = File()):
raise HTTPException(status_code=400, detail="Image-type now allowed!") raise HTTPException(status_code=400, detail="Image-type now allowed!")
session_data = EditSessionData.parse_raw(session_data) session_data = EditSessionData.parse_raw(session_data)
file_name = f"{session_data.quiz_id}--{uuid.uuid4()}" file_name = f"{session_data.quiz_id}--{uuid.uuid4()}"
# await storage.upload(file_name=file_name, file_data=file_bytes) TODO: UNCOMMENT!!!! await storage.upload(file_name=file_name, file_data=file_bytes)
await redis.lpush(f"edit_session:{edit_id}:images", file_name) await redis.lpush(f"edit_session:{edit_id}:images", file_name)
random_str = os.urandom(8).hex() random_str = os.urandom(8).hex()
await redis.set(f"edit_session:{edit_id}:pow", random_str, ex=3800) await redis.set(f"edit_session:{edit_id}:pow", random_str, ex=3800)
-1
View File
@@ -18,7 +18,6 @@
let uppyOpen = false; let uppyOpen = false;
const computePOW = async (salt: string) => { const computePOW = async (salt: string) => {
console.log('Called!');
if (pow_salt === undefined) { if (pow_salt === undefined) {
return; return;
} }
+13
View File
@@ -1,4 +1,5 @@
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import * as Sentry from '@sentry/browser';
const gen_salt = (l: number): string => { const gen_salt = (l: number): string => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -31,6 +32,7 @@ export const mint = async (
const challenge = `${ver}:${bits}:${ts}:${resource}:${ext}:${salt}`; const challenge = `${ver}:${bits}:${ts}:${resource}:${ext}:${salt}`;
let counter = 0; let counter = 0;
let result: string; let result: string;
const t0 = performance.now();
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {
const data = new TextEncoder().encode(`${challenge}:${counter.toString(16)}`); const data = new TextEncoder().encode(`${challenge}:${counter.toString(16)}`);
@@ -43,5 +45,16 @@ export const mint = async (
} }
counter += 1; counter += 1;
} }
const t1 = performance.now();
const transaction = Sentry.startTransaction({ name: 'calculatedHasCash' });
const span = transaction.startChild({
op: 'hashcash',
data: {
milliseconds_taken: t0 - t1,
bits: bits
}
});
span.finish();
transaction.finish();
return `${challenge}:${result}`; return `${challenge}:${result}`;
}; };