Skip to content

Commit

Permalink
messure the cost of sync drawings
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyijie committed Sep 4, 2023
1 parent 6430a91 commit 2447bf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
35 changes: 7 additions & 28 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,7 @@ import { config } from 'dotenv';
config();
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient({
log: [
{
emit: 'event',
level: 'query',
},
{
emit: 'stdout',
level: 'error',
},
{
emit: 'stdout',
level: 'info',
},
{
emit: 'stdout',
level: 'warn',
},
],
});
prisma.$on('query', (e) => {
console.log('Query: ' + e.query);
console.log('Params: ' + e.params);
console.log('Duration: ' + e.duration + 'ms');
});
const prisma = new PrismaClient();

var drawings = [];
var undos = [];
Expand Down Expand Up @@ -245,9 +221,12 @@ io.on('connection', async (socket) => {
});

// 客户端打开画板后,立刻推送所有涂鸦数据
socket.emit('drawings', await prisma.drawing.findMany({
orderBy: [{ id: 'asc' }],
}));
const t = new Date().getTime();
socket.emit(
'drawings',
await prisma.drawing.findMany({ orderBy: [{ id: 'asc' }] }),
() => console.log(socket.id, 'sync drawings cost', new Date().getTime() - t, 'ms')
);
});

const port = process.env.PORT || 5000;
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/WB.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default {
path: path.join(basePath, 'socket.io')
});
this.socket
.on('drawings', (drawings) => that.onRecvDrawings(drawings))
.on('drawings', (drawings, callback) => that.onRecvDrawings(drawings, callback))
.on('drawing', (drawing) => that.onRecvDrawing(drawing))
.on('undo', (stroke) => that.onUndo(stroke))
.on('delete', (strokes) => that.onDelete(strokes))
Expand Down Expand Up @@ -409,7 +409,8 @@ export default {
},

// 加载服务器数据,初始化画板
onRecvDrawings(drawings) {
onRecvDrawings(drawings, callback) {
callback();
for (const drawing of drawings) {
const { strokeId, color, opacity, size, beginPointX, beginPointY, ctrlPointX, ctrlPointY, endPointX, endPointY } = drawing;
const pen = { color, opacity, size };
Expand Down

0 comments on commit 2447bf1

Please sign in to comment.