mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(chat) Optimize the conditions for chatDemo loading (#548)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -18,7 +18,6 @@ import com.tencent.supersonic.chat.persistence.repository.ChatContextRepository;
|
||||
import com.tencent.supersonic.chat.persistence.repository.ChatQueryRepository;
|
||||
import com.tencent.supersonic.chat.persistence.repository.ChatRepository;
|
||||
import com.tencent.supersonic.chat.service.ChatService;
|
||||
import com.tencent.supersonic.chat.utils.SimilarQueryManager;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
@@ -44,14 +43,12 @@ public class ChatServiceImpl implements ChatService {
|
||||
private ChatContextRepository chatContextRepository;
|
||||
private ChatRepository chatRepository;
|
||||
private ChatQueryRepository chatQueryRepository;
|
||||
private SimilarQueryManager solvedQueryManager;
|
||||
|
||||
public ChatServiceImpl(ChatContextRepository chatContextRepository, ChatRepository chatRepository,
|
||||
ChatQueryRepository chatQueryRepository, SimilarQueryManager solvedQueryManager) {
|
||||
ChatQueryRepository chatQueryRepository) {
|
||||
this.chatContextRepository = chatContextRepository;
|
||||
this.chatRepository = chatRepository;
|
||||
this.chatQueryRepository = chatQueryRepository;
|
||||
this.solvedQueryManager = solvedQueryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -63,11 +64,16 @@ public class ChatDemoLoader implements CommandLineRunner {
|
||||
@Autowired
|
||||
private SysParameterService sysParameterService;
|
||||
|
||||
@Value("${demo.enabled:false}")
|
||||
private boolean demoEnabled;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
if (checkEnable()) {
|
||||
doRun();
|
||||
if (!checkEnable()) {
|
||||
log.info("skip load chat demo");
|
||||
return;
|
||||
}
|
||||
doRun();
|
||||
}
|
||||
|
||||
public void doRun() {
|
||||
@@ -501,7 +507,10 @@ public class ChatDemoLoader implements CommandLineRunner {
|
||||
}
|
||||
|
||||
private boolean checkEnable() {
|
||||
return chatService.getLastQuery(1L) == null;
|
||||
if (!demoEnabled) {
|
||||
return false;
|
||||
}
|
||||
return SemanticDemoLoader.isLoad();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -50,9 +49,6 @@ import java.util.List;
|
||||
public class ModelDemoDataLoader {
|
||||
|
||||
private User user = User.getFakeUser();
|
||||
|
||||
@Value("${demo.dbType:mysql}")
|
||||
private String demoDb;
|
||||
@Autowired
|
||||
private DatabaseService databaseService;
|
||||
@Autowired
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.springframework.util.CollectionUtils;
|
||||
@Component
|
||||
@Slf4j
|
||||
@Order(1)
|
||||
public class DemoLoader implements CommandLineRunner {
|
||||
public class SemanticDemoLoader implements CommandLineRunner {
|
||||
|
||||
private static boolean isLoad = false;
|
||||
|
||||
@Autowired
|
||||
private DomainService domainService;
|
||||
@@ -23,9 +25,6 @@ public class DemoLoader implements CommandLineRunner {
|
||||
@Autowired
|
||||
private BenchMarkDemoDataLoader benchMarkDemoLoader;
|
||||
|
||||
@Autowired
|
||||
private ChatDemoLoader chatDemoLoader;
|
||||
|
||||
@Value("${demo.enabled:false}")
|
||||
private boolean demoEnabled;
|
||||
|
||||
@@ -37,6 +36,7 @@ public class DemoLoader implements CommandLineRunner {
|
||||
}
|
||||
modelDataDemoLoader.doRun();
|
||||
benchMarkDemoLoader.doRun();
|
||||
isLoad = true;
|
||||
}
|
||||
|
||||
private boolean checkLoadDemo() {
|
||||
@@ -46,4 +46,8 @@ public class DemoLoader implements CommandLineRunner {
|
||||
return CollectionUtils.isEmpty(domainService.getDomainList());
|
||||
}
|
||||
|
||||
public static boolean isLoad() {
|
||||
return isLoad;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user