(improvement)(chat) Optimize the conditions for chatDemo loading (#548)

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2023-12-19 14:57:30 +08:00
committed by GitHub
parent c68df24375
commit d8930e8906
4 changed files with 21 additions and 15 deletions

View File

@@ -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.ChatQueryRepository;
import com.tencent.supersonic.chat.persistence.repository.ChatRepository; import com.tencent.supersonic.chat.persistence.repository.ChatRepository;
import com.tencent.supersonic.chat.service.ChatService; import com.tencent.supersonic.chat.service.ChatService;
import com.tencent.supersonic.chat.utils.SimilarQueryManager;
import com.tencent.supersonic.common.util.JsonUtil; import com.tencent.supersonic.common.util.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
@@ -44,14 +43,12 @@ public class ChatServiceImpl implements ChatService {
private ChatContextRepository chatContextRepository; private ChatContextRepository chatContextRepository;
private ChatRepository chatRepository; private ChatRepository chatRepository;
private ChatQueryRepository chatQueryRepository; private ChatQueryRepository chatQueryRepository;
private SimilarQueryManager solvedQueryManager;
public ChatServiceImpl(ChatContextRepository chatContextRepository, ChatRepository chatRepository, public ChatServiceImpl(ChatContextRepository chatContextRepository, ChatRepository chatRepository,
ChatQueryRepository chatQueryRepository, SimilarQueryManager solvedQueryManager) { ChatQueryRepository chatQueryRepository) {
this.chatContextRepository = chatContextRepository; this.chatContextRepository = chatContextRepository;
this.chatRepository = chatRepository; this.chatRepository = chatRepository;
this.chatQueryRepository = chatQueryRepository; this.chatQueryRepository = chatQueryRepository;
this.solvedQueryManager = solvedQueryManager;
} }
@Override @Override

View File

@@ -34,6 +34,7 @@ import com.tencent.supersonic.common.util.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -63,11 +64,16 @@ public class ChatDemoLoader implements CommandLineRunner {
@Autowired @Autowired
private SysParameterService sysParameterService; private SysParameterService sysParameterService;
@Value("${demo.enabled:false}")
private boolean demoEnabled;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
if (checkEnable()) { if (!checkEnable()) {
doRun(); log.info("skip load chat demo");
return;
} }
doRun();
} }
public void doRun() { public void doRun() {
@@ -501,7 +507,10 @@ public class ChatDemoLoader implements CommandLineRunner {
} }
private boolean checkEnable() { private boolean checkEnable() {
return chatService.getLastQuery(1L) == null; if (!demoEnabled) {
return false;
}
return SemanticDemoLoader.isLoad();
} }
} }

View File

@@ -36,7 +36,6 @@ import com.tencent.supersonic.semantic.model.domain.ModelService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -50,9 +49,6 @@ import java.util.List;
public class ModelDemoDataLoader { public class ModelDemoDataLoader {
private User user = User.getFakeUser(); private User user = User.getFakeUser();
@Value("${demo.dbType:mysql}")
private String demoDb;
@Autowired @Autowired
private DatabaseService databaseService; private DatabaseService databaseService;
@Autowired @Autowired

View File

@@ -12,7 +12,9 @@ import org.springframework.util.CollectionUtils;
@Component @Component
@Slf4j @Slf4j
@Order(1) @Order(1)
public class DemoLoader implements CommandLineRunner { public class SemanticDemoLoader implements CommandLineRunner {
private static boolean isLoad = false;
@Autowired @Autowired
private DomainService domainService; private DomainService domainService;
@@ -23,9 +25,6 @@ public class DemoLoader implements CommandLineRunner {
@Autowired @Autowired
private BenchMarkDemoDataLoader benchMarkDemoLoader; private BenchMarkDemoDataLoader benchMarkDemoLoader;
@Autowired
private ChatDemoLoader chatDemoLoader;
@Value("${demo.enabled:false}") @Value("${demo.enabled:false}")
private boolean demoEnabled; private boolean demoEnabled;
@@ -37,6 +36,7 @@ public class DemoLoader implements CommandLineRunner {
} }
modelDataDemoLoader.doRun(); modelDataDemoLoader.doRun();
benchMarkDemoLoader.doRun(); benchMarkDemoLoader.doRun();
isLoad = true;
} }
private boolean checkLoadDemo() { private boolean checkLoadDemo() {
@@ -46,4 +46,8 @@ public class DemoLoader implements CommandLineRunner {
return CollectionUtils.isEmpty(domainService.getDomainList()); return CollectionUtils.isEmpty(domainService.getDomainList());
} }
public static boolean isLoad() {
return isLoad;
}
} }