feat: Record search queries (#1554)

* Record search queries

* feat: add totalCount to the search response

* feat: add comments to explain why we use setTimeout
This commit is contained in:
Renan Filipe
2020-09-22 03:05:42 -03:00
committed by GitHub
parent 0fa8a6ed2e
commit 98626ebbaf
9 changed files with 330 additions and 54 deletions

View File

@@ -11,6 +11,7 @@ import {
Document,
Event,
Revision,
SearchQuery,
Share,
Star,
User,
@@ -586,7 +587,7 @@ router.post("documents.search", auth(), pagination(), async (ctx) => {
);
}
const results = await Document.searchForUser(user, query, {
const { results, totalCount } = await Document.searchForUser(user, query, {
includeArchived: includeArchived === "true",
includeDrafts: includeDrafts === "true",
collaboratorIds,
@@ -604,6 +605,14 @@ router.post("documents.search", auth(), pagination(), async (ctx) => {
})
);
SearchQuery.create({
userId: user.id,
teamId: user.teamId,
source: "app",
query,
results: totalCount,
});
const policies = presentPolicies(user, documents);
ctx.body = {