(improvement)(chat) add timecost aspect (#339)

This commit is contained in:
mainmain
2023-11-08 17:25:23 +08:00
committed by GitHub
parent 772d5bd3ae
commit 2cb0640a7b
3 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,14 @@
package com.tencent.supersonic.chat.service;
import java.lang.annotation.Documented;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface TimeCost {
}

View File

@@ -0,0 +1,33 @@
package com.tencent.supersonic.chat.service;
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
public class TimeCostAOP {
@Pointcut("@annotation(com.tencent.supersonic.chat.service.TimeCost)")
private void timeCostAdvicePointcut() {
}
@Around("timeCostAdvicePointcut()")
public Object timeCostAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("begin to add time cost!");
Long startTime = System.currentTimeMillis();
Object object = joinPoint.proceed();
if (object instanceof QueryResult) {
QueryResult queryResult = (QueryResult) object;
queryResult.setQueryTimeCost(System.currentTimeMillis() - startTime);
return queryResult;
}
return object;
}
}

View File

@@ -35,6 +35,7 @@ import com.tencent.supersonic.chat.service.ChatService;
import com.tencent.supersonic.chat.service.QueryService;
import com.tencent.supersonic.chat.service.SemanticService;
import com.tencent.supersonic.chat.service.StatisticsService;
import com.tencent.supersonic.chat.service.TimeCost;
import com.tencent.supersonic.chat.utils.ComponentFactory;
import com.tencent.supersonic.chat.utils.SolvedQueryManager;
import com.tencent.supersonic.common.pojo.DateConf;
@@ -208,8 +209,8 @@ public class QueryServiceImpl implements QueryService {
}
@Override
@TimeCost
public QueryResult performExecution(ExecuteQueryReq queryReq) throws Exception {
Long executeTime = System.currentTimeMillis();
ChatParseDO chatParseDO = chatService.getParseInfo(queryReq.getQueryId(),
queryReq.getParseId());
ChatQueryDO chatQueryDO = chatService.getLastQuery(queryReq.getChatId());
@@ -249,7 +250,6 @@ public class QueryServiceImpl implements QueryService {
} else {
chatService.deleteChatQuery(queryReq.getQueryId());
}
queryResult.setQueryTimeCost(System.currentTimeMillis() - executeTime);
return queryResult;
}
@@ -334,6 +334,7 @@ public class QueryServiceImpl implements QueryService {
//mainly used for executing after revising filters,for example:"fans_cnt>=100000"->"fans_cnt>500000",
//"style='流行'"->"style in ['流行','爱国']"
@Override
@TimeCost
public QueryResult executeDirectQuery(QueryDataReq queryData, User user) throws SqlParseException {
ChatParseDO chatParseDO = chatService.getParseInfo(queryData.getQueryId(),
queryData.getParseId());