@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.8.448",
3
+ "version": "1.8.449",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3,7 +3,7 @@ import sleep from "./sleep.js";
3
3
 
4
4
  export default class AsyncTaskManager {
5
5
 
6
- public rateLimit = 10;
6
+ public rateLimit = 10;
7
7
 
8
8
  private running: Set<any> = new Set();
9
9
 
@@ -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
- for (const email of pending) {
47
- try {
48
- await indexService.indexEmail(email);
49
- } catch (error) {
50
- console.error(error);
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
  }