perf: lazy instantiation uuidv4
Showing
1 changed file
with
4 additions
and
2 deletions
@@ -145,15 +145,17 @@ app.use((req, res, next) => { | @@ -145,15 +145,17 @@ app.use((req, res, next) => { | ||
145 | 145 | ||
146 | // 独立的 UDID | 146 | // 独立的 UDID |
147 | if (!req.cookies.udid || (req.yoho.isApp && req.query.udid)) { | 147 | if (!req.cookies.udid || (req.yoho.isApp && req.query.udid)) { |
148 | - let udid = uuid.v4(); | 148 | + let udid; |
149 | 149 | ||
150 | if (req.yoho.isApp && req.query.udid) { | 150 | if (req.yoho.isApp && req.query.udid) { |
151 | udid = req.query.udid; | 151 | udid = req.query.udid; |
152 | + } else { | ||
153 | + udid = uuid.v4(); | ||
152 | } | 154 | } |
153 | 155 | ||
154 | res.cookie('udid', udid, { | 156 | res.cookie('udid', udid, { |
155 | domain: 'yohobuy.com', | 157 | domain: 'yohobuy.com', |
156 | - expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) | 158 | + expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) // 1Year |
157 | }); | 159 | }); |
158 | req.cookies.udid = udid; | 160 | req.cookies.udid = udid; |
159 | } | 161 | } |
-
Please register or login to post a comment