mirror of https://github.com/fantasticit/think.git
server: improve get views
parent
5c4019c102
commit
802f7c9228
|
@ -624,7 +624,7 @@ export class DocumentService {
|
|||
|
||||
const [views, createUser] = await Promise.all([
|
||||
await this.viewService.getDocumentTotalViews(documentId),
|
||||
doc && doc.createUserId ? await this.userService.findById(doc.createUserId) : null,
|
||||
await this.userService.findById(doc.createUserId),
|
||||
]);
|
||||
|
||||
return {
|
||||
|
|
|
@ -33,8 +33,17 @@ export class ViewService {
|
|||
}
|
||||
|
||||
async getDocumentTotalViews(documentId) {
|
||||
const [, total] = await this.viewRepo.findAndCount({ documentId });
|
||||
return total;
|
||||
try {
|
||||
const count = await this.viewRepo.query(
|
||||
`SELECT COUNT(1)
|
||||
FROM view
|
||||
WHERE view.documentId = '${documentId}'
|
||||
`
|
||||
);
|
||||
return count[0]['COUNT(1)'];
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
async getDocumentViews(documentId, pagination: IPagination) {
|
||||
|
@ -64,7 +73,6 @@ export class ViewService {
|
|||
}>
|
||||
> {
|
||||
const count = 20;
|
||||
|
||||
const ret = await this.viewRepo.query(
|
||||
`
|
||||
SELECT v.documentId, v.visitedAt FROM (
|
||||
|
|
Loading…
Reference in New Issue