|
2 | 2 | * @typedef {import('../parts/common-lib.js').App} App |
3 | 3 | */ |
4 | 4 |
|
5 | | -const crypto = require('crypto'); |
6 | 5 | const log = require('../../../../api/utils/log.js')('alert:rating'); |
7 | 6 | const moment = require('moment-timezone'); |
8 | 7 | const common = require('../../../../api/utils/common.js'); |
@@ -111,14 +110,13 @@ module.exports.check = async function({ alertConfigs: alert, done, scheduledTo: |
111 | 110 | async function getRatingResponsesByDate(app, widgetId, date, period, ratings) { |
112 | 111 | const { years } = commonLib.getDateComponents(date, app.timezone); |
113 | 112 | const eventName = "[CLY]_star_rating"; |
114 | | - const collectionName = "events" + crypto |
115 | | - .createHash('sha1') |
116 | | - .update(eventName + app._id.toString()) |
117 | | - .digest('hex'); |
118 | | - |
119 | 113 | // find all segment values: |
120 | | - const records = await common.db.collection(collectionName) |
121 | | - .find({ m: String(years) + ":0" }) |
| 114 | + const records = await common.db.collection("events_data") |
| 115 | + .find({ |
| 116 | + a: app._id.toString(), |
| 117 | + e: eventName, |
| 118 | + m: String(years) + ":0", |
| 119 | + }) |
122 | 120 | .toArray(); |
123 | 121 | const segmentValueSet = new Set; |
124 | 122 | for (const record of records) { |
@@ -154,10 +152,13 @@ async function getRatingResponsesByDate(app, widgetId, date, period, ratings) { |
154 | 152 |
|
155 | 153 | /* |
156 | 154 | (async function() { |
| 155 | + if (!require("cluster").isPrimary) { |
| 156 | + return; |
| 157 | + } |
157 | 158 | await new Promise(res => setTimeout(res, 2000)); |
158 | | - const app = { _id: ObjectId("65c1f875a12e98a328d5eb9e"), timezone: "Europe/Istanbul" }; |
159 | | - const date = new Date("2024-02-07T12:00:00.000Z"); |
160 | | - const widgetId = "65c383fbb46a4d172d7c58e1"; |
| 159 | + const app = { _id: new ObjectId("68ca8d133bded4a5d888bb45"), timezone: "Europe/Istanbul" }; |
| 160 | + const date = new Date("2025-09-29T12:47:19.247Z"); |
| 161 | + const widgetId = "68ca8d133bded4a5d888bb4a"; |
161 | 162 | let monthlyData = await getRatingResponsesByDate(app, widgetId, date, "monthly", [1, 2, 3, 4, 5]); |
162 | 163 | let dailyData = await getRatingResponsesByDate(app, widgetId, date, "daily"); |
163 | 164 | console.log(monthlyData, dailyData); |
|
0 commit comments