@heliyos/heliyos-api-core 1.0.28 → 1.0.29
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/mongoose.js +41 -18
- package/package.json +1 -1
package/dist/mongoose.js
CHANGED
|
@@ -57,18 +57,16 @@ class MongoConnectionManager {
|
|
|
57
57
|
return {
|
|
58
58
|
maxPoolSize: parseInt(process.env.MONGO_MAX_POOL_SIZE || "10", 10),
|
|
59
59
|
minPoolSize: parseInt(process.env.MONGO_MIN_POOL_SIZE || "1", 10),
|
|
60
|
-
socketTimeoutMS:
|
|
60
|
+
socketTimeoutMS: 45000,
|
|
61
61
|
connectTimeoutMS: 30000,
|
|
62
62
|
serverSelectionTimeoutMS: 30000,
|
|
63
|
-
heartbeatFrequencyMS:
|
|
63
|
+
heartbeatFrequencyMS: 30000,
|
|
64
64
|
retryWrites: true,
|
|
65
65
|
retryReads: true,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
autoCreate: false, // Disable automatic index creation
|
|
71
|
-
autoIndex: false, // Disable automatic index creation
|
|
66
|
+
maxConnecting: 1,
|
|
67
|
+
minHeartbeatFrequencyMS: 2000,
|
|
68
|
+
// Add monitoring capability
|
|
69
|
+
monitorCommands: true,
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
static getInstance() {
|
|
@@ -129,15 +127,40 @@ function initializeDatabase() {
|
|
|
129
127
|
}
|
|
130
128
|
mongoose_1.default.Query.prototype.paginate = function () {
|
|
131
129
|
return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
var _a;
|
|
131
|
+
try {
|
|
132
|
+
const offset = (page - 1) * limit;
|
|
133
|
+
const startTime = Date.now();
|
|
134
|
+
const [result] = yield this.facet({
|
|
135
|
+
metadata: [{ $count: "total" }],
|
|
136
|
+
data: [{ $skip: offset }, { $limit: limit }],
|
|
137
|
+
});
|
|
138
|
+
const endTime = Date.now();
|
|
139
|
+
logger_1.logger.debug("Pagination query time:", {
|
|
140
|
+
duration: endTime - startTime,
|
|
141
|
+
page,
|
|
142
|
+
limit,
|
|
143
|
+
});
|
|
144
|
+
const total = ((_a = result.metadata[0]) === null || _a === void 0 ? void 0 : _a.total) || 0;
|
|
145
|
+
const data = result.data;
|
|
146
|
+
return {
|
|
147
|
+
data,
|
|
148
|
+
meta: {
|
|
149
|
+
page,
|
|
150
|
+
limit,
|
|
151
|
+
offset,
|
|
152
|
+
count: total,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
logger_1.logger.error("Pagination error:", {
|
|
158
|
+
error,
|
|
159
|
+
query: this.getQuery(),
|
|
160
|
+
page,
|
|
161
|
+
limit,
|
|
162
|
+
});
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
142
165
|
});
|
|
143
166
|
};
|