1 | const Constant = require('../../libraries/constant') |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
2 | const Moment = require('moment') |
||
3 | const Redis = require('../../../config/db').redis |
||
4 | const ModelStatisticsStore = require('../../../app/model/mist/statisticsStore') |
||
5 | |||
6 | var INSERT_PER_TIMES = 1000 |
||
7 | |||
8 | var statistics = async function () { |
||
9 | let accessDate = Moment().subtract(1, 'days').format('YYYY-MM-DD') |
||
10 | let statisticsDay = Moment().subtract(1, 'days').format('YYYYMMDD') |
||
11 | // let accessDate = Moment().format('YYYY-MM-DD') |
||
12 | // let statisticsDay = Moment().format('YYYYMMDD') |
||
13 | let uvCachePrefix = 'MIST:ST_UV:DATE:' + statisticsDay + ':STORE_ID:' |
||
14 | let pvCacheKey = 'MIST:ST_PV:DATE:' + statisticsDay |
||
15 | |||
16 | // 根据storeID前缀 1-9 |
||
17 | let keywords |
||
18 | let uvKeys |
||
19 | |||
20 | // insert update data |
||
21 | let insertData = [] |
||
22 | |||
23 | for (let index = 1; index < 10; index++) { |
||
24 | keywords = uvCachePrefix + index.toString() + '*' |
||
25 | uvKeys = await Redis.keys(keywords) |
||
26 | for (let i = 0; i < uvKeys.length; i++) { |
||
27 | element = uvKeys[i] |
||
0 ignored issues
–
show
|
|||
28 | let storeId = element.replace(uvCachePrefix, '') |
||
29 | |||
30 | let tmpUv = await Redis.bitcount(element) |
||
31 | let tmpPv = await Redis.hget(pvCacheKey, storeId) |
||
32 | |||
33 | let tmp = { |
||
34 | store_id: storeId, |
||
35 | access_date: accessDate, |
||
36 | pv: tmpPv, |
||
37 | uv: tmpUv, |
||
38 | } |
||
39 | // console.log(tmp) |
||
40 | // console.log('---------------------------') |
||
41 | |||
42 | insertData.push(tmp) |
||
43 | // 每1000条插入一次 |
||
44 | if (insertData.length >= INSERT_PER_TIMES) { |
||
45 | console.log('---- insert DB ---- count: ' + insertData.length) |
||
0 ignored issues
–
show
|
|||
46 | ModelStatisticsStore.add(insertData) |
||
47 | insertData.length = 0 |
||
48 | } |
||
49 | |||
50 | } |
||
51 | } |
||
52 | |||
53 | if (insertData.length > 0) { |
||
54 | console.log('---- last insert DB ---- count: ' + insertData.length) |
||
55 | await ModelStatisticsStore.add(insertData) |
||
56 | } |
||
57 | |||
58 | // update total |
||
59 | await ModelStatisticsStore.updateStatisticsTotal(accessDate) |
||
60 | console.log('ok statistics.js ' + Moment().format('YYYYMMDD HH:mm:ss')) |
||
61 | } |
||
62 | |||
63 | module.exports = statistics |