Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

improvements

daniel31x13e06f52642a78
diff --git a/lib/api/controllers/collections/collectionId/deleteCollectionById.ts b/lib/api/controllers/collections/collectionId/deleteCollectionById.ts
index 83807a7e..f2bf43ad 100644
--- a/lib/api/controllers/collections/collectionId/deleteCollectionById.ts
+++ b/lib/api/controllers/collections/collectionId/deleteCollectionById.ts
@@ -1,7 +1,8 @@
import { prisma } from "@/lib/api/db";
import getPermission from "@/lib/api/getPermission";
-import { UsersAndCollections } from "@prisma/client";
+import { Link, UsersAndCollections } from "@prisma/client";
import removeFolder from "@/lib/api/storage/removeFolder";
+import { meiliClient } from "@/lib/api/meilisearchClient";
export default async function deleteCollection(
userId: number,
@@ -33,6 +34,15 @@ export default async function deleteCollection(
await removeFromOrders(userId, collectionId);
+ await prisma.link.updateMany({
+ where: {
+ collectionId,
+ },
+ data: {
+ indexVersion: null,
+ },
+ });
+
return { response: deletedUsersAndCollectionsRelation, status: 200 };
} else if (collectionIsAccessible?.ownerId !== userId) {
return { response: "Collection is not accessible.", status: 401 };
@@ -49,14 +59,6 @@ export default async function deleteCollection(
},
});
- await prisma.link.deleteMany({
- where: {
- collection: {
- id: collectionId,
- },
- },
- });
-
removeFolder({ filePath: `archives/${collectionId}` });
removeFolder({ filePath: `archives/preview/${collectionId}` });
@@ -66,10 +68,19 @@ export default async function deleteCollection(
where: {
id: collectionId,
},
+ include: {
+ links: true,
+ },
});
});
- return { response: deletedCollection, status: 200 };
+ const { links, ...data } = deletedCollection;
+
+ const linkIds = links.map((link) => link.id);
+
+ meiliClient?.index("links").deleteDocuments(linkIds);
+
+ return { response: data, status: 200 };
}
async function deleteSubCollections(collectionId: number) {
@@ -88,6 +99,19 @@ async function deleteSubCollections(collectionId: number) {
},
});
+ const links = await prisma.link.findMany({
+ where: {
+ collectionId: subCollection.id,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ const linkIds = links.map((link) => link.id);
+
+ meiliClient?.index("links").deleteDocuments(linkIds);
+
await prisma.link.deleteMany({
where: {
collection: {
diff --git a/lib/api/controllers/collections/collectionId/updateCollectionById.ts b/lib/api/controllers/collections/collectionId/updateCollectionById.ts
index 2f78d1c9..4b360cd4 100644
--- a/lib/api/controllers/collections/collectionId/updateCollectionById.ts
+++ b/lib/api/controllers/collections/collectionId/updateCollectionById.ts
@@ -109,6 +109,11 @@ export default async function updateCollection(
_count: {
select: { links: true },
},
+ links: {
+ select: {
+ id: true,
+ },
+ },
members: {
include: {
user: {
@@ -125,5 +130,20 @@ export default async function updateCollection(
});
});
- return { response: updatedCollection, status: 200 };
+ const { links, ...dataResponse } = updatedCollection;
+
+ const linkIds = links.map((link) => link.id);
+
+ await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linkIds,
+ },
+ },
+ data: {
+ indexVersion: null,
+ },
+ });
+
+ return { response: dataResponse, status: 200 };
}
diff --git a/lib/api/controllers/tags/tagId/deleteTagById.ts b/lib/api/controllers/tags/tagId/deleteTagById.ts
index 61151840..2080f706 100644
--- a/lib/api/controllers/tags/tagId/deleteTagById.ts
+++ b/lib/api/controllers/tags/tagId/deleteTagById.ts
@@ -16,11 +16,33 @@ export default async function deleteTagById(userId: number, tagId: number) {
status: 401,
};
- const updatedTag = await prisma.tag.delete({
+ const deletedTag = await prisma.tag.delete({
where: {
id: tagId,
},
+ include: {
+ links: {
+ select: {
+ id: true,
+ },
+ },
+ },
+ });
+
+ const { links, ...data } = deletedTag;
+
+ const linkIds = links.map((link) => link.id);
+
+ await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linkIds,
+ },
+ },
+ data: {
+ indexVersion: null,
+ },
});
- return { response: updatedTag, status: 200 };
+ return { response: data, status: 200 };
}
diff --git a/lib/api/controllers/tags/tagId/updateTagById.ts b/lib/api/controllers/tags/tagId/updateTagById.ts
index 7bff0541..25abe63b 100644
--- a/lib/api/controllers/tags/tagId/updateTagById.ts
+++ b/lib/api/controllers/tags/tagId/updateTagById.ts
@@ -54,7 +54,29 @@ export default async function updateTagById(
data: {
name: name,
},
+ include: {
+ links: {
+ select: {
+ id: true,
+ },
+ },
+ },
+ });
+
+ const { links, ...data } = updatedTag;
+
+ const linkIds = links.map((link) => link.id);
+
+ await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linkIds,
+ },
+ },
+ data: {
+ indexVersion: null,
+ },
});
- return { response: updatedTag, status: 200 };
+ return { response: data, status: 200 };
}