@social-mail/social-mail-web-server 1.7.310 → 1.7.311
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/cacheFor.d.ts +1 -1
- package/dist/common/cacheFor.d.ts.map +1 -1
- package/dist/common/cacheFor.js +7 -0
- package/dist/common/cacheFor.js.map +1 -1
- package/dist/server/services/files/SiteDiskContentCache.d.ts +3 -1
- package/dist/server/services/files/SiteDiskContentCache.d.ts.map +1 -1
- package/dist/server/services/files/SiteDiskContentCache.js +5 -10
- package/dist/server/services/files/SiteDiskContentCache.js.map +1 -1
- package/dist/server/services/files/WebSiteContentService.d.ts +7 -3
- package/dist/server/services/files/WebSiteContentService.d.ts.map +1 -1
- package/dist/server/services/files/WebSiteContentService.js +57 -41
- package/dist/server/services/files/WebSiteContentService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/cacheFor.ts +8 -1
- package/src/server/services/files/SiteDiskContentCache.ts +6 -16
- package/src/server/services/files/WebSiteContentService.ts +47 -41
package/package.json
CHANGED
package/src/common/cacheFor.ts
CHANGED
|
@@ -19,7 +19,14 @@ export class ObjectCache<T> {
|
|
|
19
19
|
return tc;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
clear(name
|
|
22
|
+
clear(name?: keyof T) {
|
|
23
|
+
if (!name) {
|
|
24
|
+
for (const element of this.cache.values()) {
|
|
25
|
+
element.clear();
|
|
26
|
+
}
|
|
27
|
+
this.cache.clear();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
23
30
|
this.cache.get(name)?.clear();
|
|
24
31
|
}
|
|
25
32
|
};
|
|
@@ -4,7 +4,7 @@ import { join } from "path";
|
|
|
4
4
|
import BaseDiskCache from "../../../common/BaseDiskCache.js";
|
|
5
5
|
import { globalEnv } from "../../../common/globalEnv.js";
|
|
6
6
|
import MessagingService from "../message-events/MessagingService.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ObjectCache } from "../../../common/cacheFor.js";
|
|
8
8
|
|
|
9
9
|
@RegisterSingleton
|
|
10
10
|
export default class SiteDiskContentCache extends ServiceObject {
|
|
@@ -12,26 +12,16 @@ export default class SiteDiskContentCache extends ServiceObject {
|
|
|
12
12
|
@Inject
|
|
13
13
|
ms: MessagingService;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
cache: ObjectCache<any> = new ObjectCache();
|
|
16
|
+
|
|
17
|
+
htmlCache = new BaseDiskCache({
|
|
18
|
+
root: join(globalEnv.tmpDir, "site-html-cache", "html"),
|
|
17
19
|
keepTTLSeconds: 24*60*60
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
postInit() {
|
|
21
23
|
this.ms.snapshotRefresh.on(({ folderID }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (folderID === 0) {
|
|
25
|
-
// we need to refresh everything...
|
|
26
|
-
this.htmlFileCache.clear().catch(console.error);
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// at zero all host to snapshot map will be stored
|
|
32
|
-
this.htmlFileCache.clearFolder("0").catch(console.error);
|
|
33
|
-
this.htmlFileCache.clearFolder(folderID.toString()).catch(console.error);
|
|
34
|
-
|
|
24
|
+
this.cache.clear();
|
|
35
25
|
});
|
|
36
26
|
}
|
|
37
27
|
|
|
@@ -12,15 +12,20 @@ import TempFileService from "../../storage/TempFileService.js";
|
|
|
12
12
|
import MessagingService from "../message-events/MessagingService.js";
|
|
13
13
|
import SiteDiskContentCache from "./SiteDiskContentCache.js";
|
|
14
14
|
import SocialMailContext from "../../model/SocialMailContext.js";
|
|
15
|
+
import { cacheFor, ICacheContainer, ObjectCache } from "../../../common/cacheFor.js";
|
|
15
16
|
|
|
16
17
|
@RegisterScoped
|
|
17
|
-
export default class WebSiteContentService
|
|
18
|
+
export default class WebSiteContentService
|
|
19
|
+
extends ServiceObject
|
|
20
|
+
implements ICacheContainer<WebSiteContentService> {
|
|
18
21
|
|
|
19
22
|
@Inject
|
|
20
23
|
dbConfig: DBConfig;
|
|
21
24
|
|
|
22
25
|
@Inject
|
|
23
|
-
|
|
26
|
+
siteCache: SiteDiskContentCache;
|
|
27
|
+
|
|
28
|
+
cache: ObjectCache<WebSiteContentService>;
|
|
24
29
|
|
|
25
30
|
@Inject
|
|
26
31
|
tfs: TempFileService;
|
|
@@ -28,32 +33,34 @@ export default class WebSiteContentService {
|
|
|
28
33
|
@Inject
|
|
29
34
|
db: SocialMailContext;
|
|
30
35
|
|
|
36
|
+
postInit() {
|
|
37
|
+
this.cache = this.siteCache.cache;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@cacheFor()
|
|
31
41
|
async getCurrentSnapshotFolder(host) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
.some((
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return { snapshotFolderID: appFileID };
|
|
44
|
-
});
|
|
42
|
+
const file = await this.db.appFiles
|
|
43
|
+
.where({ host }, (p) =>
|
|
44
|
+
(x) => x.currentVersionWebSites
|
|
45
|
+
.some((w) => w.hosts
|
|
46
|
+
.some((h) => h.host === p.host)))
|
|
47
|
+
.first();
|
|
48
|
+
if (!file) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { appFileID } = file;
|
|
52
|
+
return { snapshotFolderID: appFileID };
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
@cacheFor()
|
|
47
56
|
async getWebSite(host) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return { folderID, currency, fromEmail, supportEmail };
|
|
56
|
-
});
|
|
57
|
+
const folder = await this.db.websiteFolders.where({ host }, (p) => (x) => x.hosts.some((s) => s.host === p.host))
|
|
58
|
+
.first();
|
|
59
|
+
if (!folder) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const { folderID, currency, fromEmail, supportEmail } = folder;
|
|
63
|
+
return { folderID, currency, fromEmail, supportEmail };
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
async getFile(folderID, ... path: string[]) {
|
|
@@ -64,22 +71,21 @@ export default class WebSiteContentService {
|
|
|
64
71
|
return this.tfs.downloadFileContent(fileInfo.fileContentID, fileInfo);
|
|
65
72
|
}
|
|
66
73
|
|
|
74
|
+
@cacheFor()
|
|
67
75
|
async getFileInfo(folderID, ... path: string[]): Promise<{ name, contentType, appFileID, url, fileContentID }> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return await this.getFileInfo(child.appFileID, ... paths);
|
|
82
|
-
});
|
|
76
|
+
const [top, ... paths] = path;
|
|
77
|
+
const child = await this.db.appFiles
|
|
78
|
+
.where({ folderID, top },(p) => (x) => x.parentID === p.folderID && x.name === p.top)
|
|
79
|
+
.orderBy(void 0, (p) => (x) => x.isDeleted)
|
|
80
|
+
.include((x) => x.fileContent)
|
|
81
|
+
.first();
|
|
82
|
+
if (!child) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (paths.length === 0) {
|
|
86
|
+
return { name: child.name, contentType: child.contentType, appFileID: child.appFileID, url: child.url, fileContentID: child.fileContentID };
|
|
87
|
+
}
|
|
88
|
+
return await this.getFileInfo(child.appFileID, ... paths);
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
async getSnapshotFile({ snapshotFolderID }, path: string[]) {
|
|
@@ -105,14 +111,14 @@ export default class WebSiteContentService {
|
|
|
105
111
|
return file;
|
|
106
112
|
}
|
|
107
113
|
const htmlFilePath = join(folderID.toString(), "transformed", ... path);
|
|
108
|
-
return this.
|
|
114
|
+
return this.siteCache.htmlCache.getOrCreateAsync(htmlFilePath, async (cf) => {
|
|
109
115
|
await this.transformHtml(file, cf);
|
|
110
116
|
});
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
async transformHtml(src: LocalFile, dest: LocalFile) {
|
|
114
120
|
|
|
115
|
-
const packageReplacements = await this.
|
|
121
|
+
const packageReplacements = await this.siteCache.htmlCache.getOrCreateJsonAsync("packages", async () => {
|
|
116
122
|
const config = this.dbConfig;
|
|
117
123
|
|
|
118
124
|
const packages = [
|