mirror of https://github.com/fantasticit/think.git
server: fix view record time
This commit is contained in:
parent
bdfdef3cd3
commit
5e6f283032
|
@ -19,16 +19,22 @@ export class ViewService {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async create({ userId = 'public', documentId, userAgent }) {
|
async create({ userId = 'public', documentId, userAgent }) {
|
||||||
const data = {
|
const old = await this.viewRepo.findOne({ documentId, userId });
|
||||||
|
let data;
|
||||||
|
|
||||||
|
if (old) {
|
||||||
|
data = await this.viewRepo.merge(old, {
|
||||||
|
updatedAt: convertDateToMysqlTimestamp(Date.now()),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
data = await this.viewRepo.create({
|
||||||
userId,
|
userId,
|
||||||
documentId,
|
documentId,
|
||||||
originUserAgent: userAgent,
|
originUserAgent: userAgent,
|
||||||
parsedUserAgent: parseUserAgent(userAgent).text,
|
parsedUserAgent: parseUserAgent(userAgent).text,
|
||||||
};
|
});
|
||||||
|
}
|
||||||
const res = await this.viewRepo.create(data);
|
const ret = await this.viewRepo.save(data);
|
||||||
const ret = await this.viewRepo.save(res);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +80,10 @@ export class ViewService {
|
||||||
const count = 20;
|
const count = 20;
|
||||||
|
|
||||||
const ret = await this.viewRepo.query(
|
const ret = await this.viewRepo.query(
|
||||||
`SELECT documentId, ANY_VALUE(created_at) as visitedAt
|
`SELECT documentId, ANY_VALUE(updated_at) as visitedAt
|
||||||
FROM view
|
FROM view
|
||||||
WHERE view.userId = '${userId}'
|
WHERE view.userId = '${userId}'
|
||||||
AND (view.created_at BETWEEN '${from}' AND '${end}')
|
AND (view.updated_at BETWEEN '${from}' AND '${end}')
|
||||||
GROUP BY documentId
|
GROUP BY documentId
|
||||||
LIMIT ${count}
|
LIMIT ${count}
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue