Skip to content

Commit 88af2ee

Browse files
author
Cihad Tekin
committed
[alerts] Hotfix: migrated to the new events collection
1 parent 9fd9a15 commit 88af2ee

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

plugins/alerts/api/alertModules/events.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @typedef {import('../parts/common-lib.js').App} App
33
*/
44

5-
const crypto = require('crypto');
65
const log = require('../../../../api/utils/log.js')('alert:events');
76
const moment = require('moment-timezone');
87
const common = require('../../../../api/utils/common.js');
@@ -101,14 +100,10 @@ async function getEventMetricByDate(app, event, metric, date, period, segments)
101100
if (segments) {
102101
segmentKeys = Object.keys(segments);
103102
}
104-
105-
const collectionName = "events" + crypto
106-
.createHash('sha1')
107-
.update(event + app._id.toString())
108-
.digest('hex');
109-
110-
const records = await common.db.collection(collectionName)
103+
const records = await common.db.collection("events_data")
111104
.find({
105+
a: app._id.toString(),
106+
e: event,
112107
m: monthFilter,
113108
s: { $in: segmentKeys },
114109
})
@@ -162,11 +157,13 @@ async function getEventMetricByDate(app, event, metric, date, period, segments)
162157
}
163158
/*
164159
(async function() {
160+
if (!require("cluster").isPrimary) {
161+
return;
162+
}
165163
await new Promise(res => setTimeout(res, 2000));
166-
const app = { _id: "65c1f875a12e98a328d5eb9e", timezone: "Europe/Istanbul" };
167-
const date = new Date("2024-01-02T12:47:19.247Z");
168-
const date2 = new Date("2024-01-03T13:47:19.247Z");
169-
const event = "Checkout";
164+
const app = { _id: "67fff00d901abe2f8cc57646", timezone: "Europe/Istanbul" };
165+
const date = new Date("2025-02-02T12:47:19.247Z");
166+
const event = "Product Viewed";
170167
const prop = "c";
171168
172169
const hourly = await getEventMetricByDate(app, event, prop, date, "hourly");

plugins/alerts/api/alertModules/rating.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @typedef {import('../parts/common-lib.js').App} App
33
*/
44

5-
const crypto = require('crypto');
65
const log = require('../../../../api/utils/log.js')('alert:rating');
76
const moment = require('moment-timezone');
87
const common = require('../../../../api/utils/common.js');
@@ -111,14 +110,13 @@ module.exports.check = async function({ alertConfigs: alert, done, scheduledTo:
111110
async function getRatingResponsesByDate(app, widgetId, date, period, ratings) {
112111
const { years } = commonLib.getDateComponents(date, app.timezone);
113112
const eventName = "[CLY]_star_rating";
114-
const collectionName = "events" + crypto
115-
.createHash('sha1')
116-
.update(eventName + app._id.toString())
117-
.digest('hex');
118-
119113
// 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+
})
122120
.toArray();
123121
const segmentValueSet = new Set;
124122
for (const record of records) {
@@ -154,10 +152,13 @@ async function getRatingResponsesByDate(app, widgetId, date, period, ratings) {
154152

155153
/*
156154
(async function() {
155+
if (!require("cluster").isPrimary) {
156+
return;
157+
}
157158
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";
161162
let monthlyData = await getRatingResponsesByDate(app, widgetId, date, "monthly", [1, 2, 3, 4, 5]);
162163
let dailyData = await getRatingResponsesByDate(app, widgetId, date, "daily");
163164
console.log(monthlyData, dailyData);

0 commit comments

Comments
 (0)