joye-backend-utility 8.0.10 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/schema/user_analytic.js +10 -1
- package/dist/userAnalytic.d.ts +2 -0
- package/dist/userAnalytic.js +8 -0
- package/dist/userAnalyticIndexes.d.ts +31 -0
- package/dist/userAnalyticIndexes.js +21 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { createHashPassword, createUuid } from './util';
|
|
|
4
4
|
export { createToken, jwtVerify } from './jwt';
|
|
5
5
|
export { getPreviousWorkday, get2ndLastPreviousWorkday, addDays, addMinutes, addYears, getCurrentDateTime, getCurrentUtcTime, newDate, getDatesBetweenRange, getMoment, getCurrentEpoch, } from './dateTime';
|
|
6
6
|
export { RedisClient } from './redisClient';
|
|
7
|
+
export { hasDailySuggestionFlag } from './userAnalytic';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
|
|
3
|
+
exports.hasDailySuggestionFlag = exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
|
|
4
4
|
const database_1 = require("./database");
|
|
5
5
|
exports.default = database_1.default;
|
|
6
6
|
var util_1 = require("./util");
|
|
@@ -24,3 +24,5 @@ Object.defineProperty(exports, "getMoment", { enumerable: true, get: function ()
|
|
|
24
24
|
Object.defineProperty(exports, "getCurrentEpoch", { enumerable: true, get: function () { return dateTime_1.getCurrentEpoch; } });
|
|
25
25
|
var redisClient_1 = require("./redisClient");
|
|
26
26
|
Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redisClient_1.RedisClient; } });
|
|
27
|
+
var userAnalytic_1 = require("./userAnalytic");
|
|
28
|
+
Object.defineProperty(exports, "hasDailySuggestionFlag", { enumerable: true, get: function () { return userAnalytic_1.hasDailySuggestionFlag; } });
|
|
@@ -125,6 +125,12 @@ const UserAnalytic = new mongoose_1.Schema({
|
|
|
125
125
|
dailySuggestion: {
|
|
126
126
|
type: Object,
|
|
127
127
|
required: false,
|
|
128
|
+
// Never add index: true or compound index on this field — large payload, high write RU.
|
|
129
|
+
},
|
|
130
|
+
/** Denormalized from `dailySuggestion != null` for indexed queue-cron filters (avoid `$ne: null`). */
|
|
131
|
+
hasDailySuggestion: {
|
|
132
|
+
type: Boolean,
|
|
133
|
+
required: false,
|
|
128
134
|
},
|
|
129
135
|
fallbackData: {
|
|
130
136
|
// To show the data is a fallback data from UI initiated /emotion-data request
|
|
@@ -137,7 +143,10 @@ const UserAnalytic = new mongoose_1.Schema({
|
|
|
137
143
|
required: false,
|
|
138
144
|
},
|
|
139
145
|
});
|
|
146
|
+
// Allowed compound indexes only — never add `dailySuggestion` (large object → high write RU).
|
|
147
|
+
// `autoIndex` is false in `database.ts`; create indexes manually in Cosmos if needed.
|
|
140
148
|
UserAnalytic.index({ employeeId: 1, weekNumber: -1, year: -1, date: -1 });
|
|
141
149
|
UserAnalytic.index({ employeeId: 1, month: -1, year: -1, date: -1 });
|
|
142
|
-
UserAnalytic.index({ year: 1, weekNumber: 1, bucket: 1 });
|
|
150
|
+
UserAnalytic.index({ year: 1, weekNumber: 1, bucket: 1, _id: 1 });
|
|
151
|
+
UserAnalytic.index({ year: 1, weekNumber: 1, hasDailySuggestion: 1, bucket: 1, _id: 1 });
|
|
143
152
|
exports.UserAnalyticSchema = UserAnalytic;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasDailySuggestionFlag = void 0;
|
|
4
|
+
/** Cosmos-indexable flag: true when `dailySuggestion` is stored on `User_Analytic`. */
|
|
5
|
+
function hasDailySuggestionFlag(dailySuggestion) {
|
|
6
|
+
return dailySuggestion != null;
|
|
7
|
+
}
|
|
8
|
+
exports.hasDailySuggestionFlag = hasDailySuggestionFlag;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `User_Analytic` Cosmos/Mongo index names.
|
|
3
|
+
*
|
|
4
|
+
* Do NOT index `dailySuggestion` (large object) — it inflates write RU on every upsert.
|
|
5
|
+
* Use `hasDailySuggestion` (boolean) in compound indexes instead.
|
|
6
|
+
*/
|
|
7
|
+
/** Manually created in Cosmos for old `$ne: null` cron filter — drop in production. */
|
|
8
|
+
export declare const LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP: readonly ["weekNumber_-1_year_-1_dailySuggestion_1", "weekNumber_1_year_1_dailySuggestion_1"];
|
|
9
|
+
/** Mongoose/Cosmos compound indexes defined in `user_analytic` schema (create if missing). */
|
|
10
|
+
export declare const USER_ANALYTIC_COMPOUND_INDEX_SPECS: readonly [{
|
|
11
|
+
readonly employeeId: 1;
|
|
12
|
+
readonly weekNumber: -1;
|
|
13
|
+
readonly year: -1;
|
|
14
|
+
readonly date: -1;
|
|
15
|
+
}, {
|
|
16
|
+
readonly employeeId: 1;
|
|
17
|
+
readonly month: -1;
|
|
18
|
+
readonly year: -1;
|
|
19
|
+
readonly date: -1;
|
|
20
|
+
}, {
|
|
21
|
+
readonly year: 1;
|
|
22
|
+
readonly weekNumber: 1;
|
|
23
|
+
readonly bucket: 1;
|
|
24
|
+
readonly _id: 1;
|
|
25
|
+
}, {
|
|
26
|
+
readonly year: 1;
|
|
27
|
+
readonly weekNumber: 1;
|
|
28
|
+
readonly hasDailySuggestion: 1;
|
|
29
|
+
readonly bucket: 1;
|
|
30
|
+
readonly _id: 1;
|
|
31
|
+
}];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `User_Analytic` Cosmos/Mongo index names.
|
|
4
|
+
*
|
|
5
|
+
* Do NOT index `dailySuggestion` (large object) — it inflates write RU on every upsert.
|
|
6
|
+
* Use `hasDailySuggestion` (boolean) in compound indexes instead.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.USER_ANALYTIC_COMPOUND_INDEX_SPECS = exports.LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP = void 0;
|
|
10
|
+
/** Manually created in Cosmos for old `$ne: null` cron filter — drop in production. */
|
|
11
|
+
exports.LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP = [
|
|
12
|
+
'weekNumber_-1_year_-1_dailySuggestion_1',
|
|
13
|
+
'weekNumber_1_year_1_dailySuggestion_1',
|
|
14
|
+
];
|
|
15
|
+
/** Mongoose/Cosmos compound indexes defined in `user_analytic` schema (create if missing). */
|
|
16
|
+
exports.USER_ANALYTIC_COMPOUND_INDEX_SPECS = [
|
|
17
|
+
{ employeeId: 1, weekNumber: -1, year: -1, date: -1 },
|
|
18
|
+
{ employeeId: 1, month: -1, year: -1, date: -1 },
|
|
19
|
+
{ year: 1, weekNumber: 1, bucket: 1, _id: 1 },
|
|
20
|
+
{ year: 1, weekNumber: 1, hasDailySuggestion: 1, bucket: 1, _id: 1 },
|
|
21
|
+
];
|