document-drive 1.0.0-alpha.82 → 1.0.0-alpha.83
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 +1 -1
- package/src/cache/redis.ts +21 -6
- package/src/queue/base.ts +1 -1
- package/src/storage/prisma.ts +20 -27
package/package.json
CHANGED
package/src/cache/redis.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Document } from "document-model/document";
|
|
2
2
|
import { ICache } from "./types";
|
|
3
3
|
import type { RedisClientType } from "redis";
|
|
4
|
-
import { logger } from "../utils/logger";
|
|
5
4
|
|
|
6
5
|
class RedisCache implements ICache {
|
|
7
6
|
private redis: RedisClientType;
|
|
7
|
+
private timeoutInSeconds: number;
|
|
8
8
|
|
|
9
|
-
constructor(redis: RedisClientType) {
|
|
9
|
+
constructor(redis: RedisClientType, timeoutInSeconds: number | undefined = 5 * 60) {
|
|
10
10
|
this.redis = redis;
|
|
11
|
-
this.
|
|
11
|
+
this.timeoutInSeconds = timeoutInSeconds;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private static _getId(drive: string, id: string) {
|
|
15
|
+
return `cache:${drive}:${id}`;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
async setDocument(drive: string, id: string, document: Document) {
|
|
@@ -21,17 +25,28 @@ class RedisCache implements ICache {
|
|
|
21
25
|
return e;
|
|
22
26
|
});
|
|
23
27
|
const doc = { ...document, operations: { global, local } }
|
|
24
|
-
|
|
28
|
+
const redisId = RedisCache._getId(drive, id);
|
|
29
|
+
const result = await this.redis.set(redisId, JSON.stringify(doc), {
|
|
30
|
+
EX: this.timeoutInSeconds ? this.timeoutInSeconds : undefined
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (result === 'OK') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
async getDocument(drive: string, id: string) {
|
|
28
|
-
const
|
|
41
|
+
const redisId = RedisCache._getId(drive, id);
|
|
42
|
+
const doc = await this.redis.get(redisId);
|
|
29
43
|
|
|
30
44
|
return doc ? JSON.parse(doc) as Document : undefined;
|
|
31
45
|
}
|
|
32
46
|
|
|
33
47
|
async deleteDocument(drive: string, id: string) {
|
|
34
|
-
|
|
48
|
+
const redisId = RedisCache._getId(drive, id);
|
|
49
|
+
return (await this.redis.del(redisId)) > 0;
|
|
35
50
|
}
|
|
36
51
|
}
|
|
37
52
|
|
package/src/queue/base.ts
CHANGED
|
@@ -253,6 +253,6 @@ export class BaseQueueManager implements IQueueManager {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
protected getQueueId(driveId: string, documentId?: string) {
|
|
256
|
-
return
|
|
256
|
+
return `queue:${driveId}${documentId ? `:${documentId}` : ''}`;
|
|
257
257
|
}
|
|
258
258
|
}
|
package/src/storage/prisma.ts
CHANGED
|
@@ -31,14 +31,14 @@ import {
|
|
|
31
31
|
|
|
32
32
|
type Transaction =
|
|
33
33
|
| Omit<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
PrismaClient<Prisma.PrismaClientOptions, never>,
|
|
35
|
+
| '$connect'
|
|
36
|
+
| '$disconnect'
|
|
37
|
+
| '$on'
|
|
38
|
+
| '$transaction'
|
|
39
|
+
| '$use'
|
|
40
|
+
| '$extends'
|
|
41
|
+
>
|
|
42
42
|
| ExtendedPrismaClient;
|
|
43
43
|
|
|
44
44
|
function storageToOperation(
|
|
@@ -495,21 +495,21 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
async deleteDocument(drive: string, id: string) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
498
|
+
try {
|
|
499
|
+
await this.db.document.deleteMany({
|
|
500
|
+
where: {
|
|
501
501
|
driveId: drive,
|
|
502
502
|
id: id
|
|
503
503
|
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
}
|
|
504
|
+
});
|
|
505
|
+
} catch (e: any) {
|
|
506
|
+
// Ignore Error: P2025: An operation failed because it depends on one or more records that were required but not found.
|
|
507
|
+
if ((e.code && e.code === "P2025") || (e.message && e.message.includes("An operation failed because it depends on one or more records that were required but not found."))) {
|
|
508
|
+
return;
|
|
511
509
|
}
|
|
512
|
-
|
|
510
|
+
|
|
511
|
+
throw e;
|
|
512
|
+
}
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
async getDrives() {
|
|
@@ -541,13 +541,6 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
async deleteDrive(id: string) {
|
|
544
|
-
// delete drive documents and operations
|
|
545
|
-
await this.db.document.deleteMany({
|
|
546
|
-
where: {
|
|
547
|
-
driveId: id
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
|
|
551
544
|
// delete drive and associated slug
|
|
552
545
|
await this.db.drive.deleteMany({
|
|
553
546
|
where: {
|
|
@@ -555,7 +548,7 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
555
548
|
}
|
|
556
549
|
});
|
|
557
550
|
|
|
558
|
-
// delete drive
|
|
551
|
+
// delete drive document and its operations
|
|
559
552
|
await this.deleteDocument('drives', id);
|
|
560
553
|
}
|
|
561
554
|
|