@social-mail/social-mail-web-server 1.8.448 → 1.8.449
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/common/AsyncTaskManager.d.ts.map +1 -1
- package/dist/common/AsyncTaskManager.js.map +1 -1
- package/dist/server/workflows/email/index/IndexEmailContentWorkflow.d.ts +5 -2
- package/dist/server/workflows/email/index/IndexEmailContentWorkflow.d.ts.map +1 -1
- package/dist/server/workflows/email/index/IndexEmailContentWorkflow.js +82 -15
- package/dist/server/workflows/email/index/IndexEmailContentWorkflow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/AsyncTaskManager.ts +1 -1
- package/src/server/workflows/email/index/IndexEmailContentWorkflow.ts +21 -13
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import Inject from "@entity-access/entity-access/dist/di/di.js";
|
|
2
|
+
import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
|
|
3
3
|
import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
|
|
4
4
|
import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
|
|
5
5
|
import SocialMailContext from "../../../model/SocialMailContext.js";
|
|
6
6
|
import IndexEmailService from "../../../services/emails/IndexEmailService.js";
|
|
7
7
|
import TimeSpan from "@entity-access/entity-access/dist/types/TimeSpan.js";
|
|
8
8
|
import { globalEnv } from "../../../../common/globalEnv.js";
|
|
9
|
+
import AsyncTaskManager from "../../../../common/AsyncTaskManager.js";
|
|
9
10
|
|
|
10
11
|
export default class IndexEmailContentWorkflow extends Workflow {
|
|
11
12
|
|
|
@@ -24,13 +25,11 @@ export default class IndexEmailContentWorkflow extends Workflow {
|
|
|
24
25
|
|
|
25
26
|
@UniqueActivity
|
|
26
27
|
async index(
|
|
27
|
-
@Inject db?: SocialMailContext
|
|
28
|
-
@Inject indexService?: IndexEmailService
|
|
28
|
+
@Inject db?: SocialMailContext
|
|
29
29
|
) {
|
|
30
30
|
|
|
31
31
|
for(let i = 0;i<1000;i++) {
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
const pending = await db.emails.where(void 0, (p) => (x) => x.searchIndexed === false
|
|
35
34
|
&& x.statePostReceiveInvoked === true)
|
|
36
35
|
.orderByDescending(void 0, (p) => (x) => x.emailID)
|
|
@@ -43,17 +42,26 @@ export default class IndexEmailContentWorkflow extends Workflow {
|
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
const { emailID } = email;
|
|
53
|
-
await db.emails.statements.update({ searchIndexed: true }, { emailID });
|
|
54
|
-
}
|
|
45
|
+
const at = new AsyncTaskManager();
|
|
46
|
+
at.rateLimit = 5;
|
|
47
|
+
|
|
48
|
+
await Promise.all(pending.map((x) => at.run(() => this.indexEmail(x))));
|
|
49
|
+
|
|
55
50
|
db.changeSet.clear();
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
|
|
54
|
+
async indexEmail(email: { emailID: number; textBody: string; }) {
|
|
55
|
+
using scope = ServiceProvider.createScope(this.context);
|
|
56
|
+
const db = scope.resolve(SocialMailContext);
|
|
57
|
+
const indexService = scope.resolve(IndexEmailService);
|
|
58
|
+
try {
|
|
59
|
+
await indexService.indexEmail(email);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(error);
|
|
62
|
+
}
|
|
63
|
+
const { emailID } = email;
|
|
64
|
+
await db.emails.statements.update({ searchIndexed: true }, { emailID });
|
|
65
|
+
}
|
|
66
|
+
|
|
59
67
|
}
|