zwhui 1 年間 前
コミット
ef0bad182a

+ 17 - 13
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -114,6 +114,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
 
     private final MidjourneySessionMapper midjourneySessionMapper;
 
+    private final ConcurrentHashMap<String, Object> lockMap = new ConcurrentHashMap<>();
+
+
     @Override
     public MidjourneyUser getUser(String userToken) {
         if(StringUtils.isBlank(userToken)){
@@ -768,16 +771,16 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                 //失败返还次数
                 if ("FAILURE".equals(conversation.getStatus()) && !dbConversation.getStatus().equals("MODEL")){
                     Integer mode = dbConversation.getMode();
-                    if (StringUtils.equals("未知频道",conversation.getFailReason())) {
-                        redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
-                        String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
-                        TASK_EXECUTOR.execute(() -> {
-                            MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
-                            if (account.getStatus()) {
-                                midjourneyAccountService.updateStatus(account.getId());
-                            }
-                        });
-                    }
+//                    if (StringUtils.equals("未知频道",conversation.getFailReason())) {
+//                        redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
+//                        String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
+//                        TASK_EXECUTOR.execute(() -> {
+//                            MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
+//                            if (account.getStatus()) {
+//                                midjourneyAccountService.updateStatus(account.getId());
+//                            }
+//                        });
+//                    }
                     Object num = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + userId);
                     LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
                             .eq(MidjourneyUser::getId, userId);
@@ -1115,7 +1118,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
     public void handleCallback(MidjourneyUserConversation conversation) {
        String key = RedisService.key.MIDJOURNEY_PROGRESS.getName() + conversation.getTaskId();
 
-        synchronized (key.intern()) {
+        synchronized (conversation.getTaskId()) {
             String currentProgressStr = redisService.getStr(key);
             if(StringUtils.isNotBlank(currentProgressStr)){
                 if (StringUtils.isNumeric(currentProgressStr)) {
@@ -1126,8 +1129,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                     }
                 }
             }else {
-                redisService.set(key, 0, RedisService.key.MIDJOURNEY_PROGRESS.getTimeout());
-                sendProgressToClient(conversation);
+                if (redisService.setNx(key, 0, RedisService.key.MIDJOURNEY_PROGRESS.getTimeout())) {
+                    sendProgressToClient(conversation);
+                }
             }
 
         }