From ddebbbf024427a0b10d398a2fb09d8c14a8267f5 Mon Sep 17 00:00:00 2001 From: haishanh Date: Tue, 30 Oct 2018 15:55:33 +0800 Subject: [PATCH] fix(logs): add random str to each log id to prevent key collision --- src/api/logs.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/logs.js b/src/api/logs.js index 291ea26..779a5b4 100644 --- a/src/api/logs.js +++ b/src/api/logs.js @@ -6,6 +6,10 @@ import { const endpoint = '/logs'; const textDecoder = new TextDecoder('utf-8', { stream: true }); +const getRandomStr = () => { + return Math.floor((1 + Math.random()) * 0x10000).toString(16); +}; + function getURLAndInit() { const c = getAPIConfig(); const baseURL = getAPIBaseURL(c); @@ -28,7 +32,7 @@ const store = { const time = now.toLocaleString('zh-Hans'); // mutate input param in place intentionally o.time = time; - o.id = now - 0; + o.id = now - 0 + getRandomStr(); o.even = even = !even; this.logs.unshift(o); if (this.logs.length > this.size) this.logs.pop();