📈 Added analytics on time spent running PoW-stuff
This commit is contained in:
@@ -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!")
|
||||
session_data = EditSessionData.parse_raw(session_data)
|
||||
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)
|
||||
random_str = os.urandom(8).hex()
|
||||
await redis.set(f"edit_session:{edit_id}:pow", random_str, ex=3800)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
let uppyOpen = false;
|
||||
|
||||
const computePOW = async (salt: string) => {
|
||||
console.log('Called!');
|
||||
if (pow_salt === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import * as Sentry from '@sentry/browser';
|
||||
|
||||
const gen_salt = (l: number): string => {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
@@ -31,6 +32,7 @@ export const mint = async (
|
||||
const challenge = `${ver}:${bits}:${ts}:${resource}:${ext}:${salt}`;
|
||||
let counter = 0;
|
||||
let result: string;
|
||||
const t0 = performance.now();
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const data = new TextEncoder().encode(`${challenge}:${counter.toString(16)}`);
|
||||
@@ -43,5 +45,16 @@ export const mint = async (
|
||||
}
|
||||
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}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user