Skip to content

Commit

Permalink
v5.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Aug 27, 2024
1 parent 7876ec0 commit 54bfef2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Midjourney.API/DiscordAccountInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ public async Task Initialize(params DiscordAccountConfig[] appends)
if (account == null)
{
account = DiscordAccount.Create(configAccount);

db.Add(account);

accounts.Add(account);
}
}
Expand Down Expand Up @@ -793,7 +793,6 @@ public async Task ReconnectAccount(DiscordAccount account)
if (disInstance != null)
{
_discordLoadBalancer.RemoveInstance(disInstance);

disInstance.Dispose();
}
}
Expand Down Expand Up @@ -821,6 +820,7 @@ public void DeleteAccount(string id)
var disInstance = _discordLoadBalancer.GetDiscordInstance(model.ChannelId);
if (disInstance != null)
{
_discordLoadBalancer.RemoveInstance(disInstance);
disInstance.Dispose();
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/Midjourney.Infrastructure/Data/LiteDBRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ public void Init()
public void Add(T entity)
{
var col = _db.GetCollection<T>();
entity.Id = col.Insert(entity);
var id = col.Insert(entity);

if (!string.IsNullOrWhiteSpace(id))
{
entity.Id = id;
}
}

/// <summary>
Expand Down Expand Up @@ -362,7 +367,7 @@ public void Delete(string id)
/// <returns></returns>
public T Get(string id)
{
return _db.GetCollection<T>().FindOne(c => c.Id == id);
return _db.GetCollection<T>().FindById(id);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Midjourney.Infrastructure/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class GlobalConfiguration
/// <summary>
/// 版本号
/// </summary>
public static string Version { get; set; } = "v5.5.3";
public static string Version { get; set; } = "v5.5.5";

/// <summary>
/// 全局配置项
Expand Down
23 changes: 15 additions & 8 deletions src/Midjourney.Infrastructure/Services/DiscordInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,27 @@ public DiscordAccount Account
{
lock (_lockAccount)
{
_account = _cache.GetOrCreate($"account:{_account.Id}", (c) =>
if (!string.IsNullOrWhiteSpace(_account?.Id))
{
c.SetAbsoluteExpiration(TimeSpan.FromMinutes(2));
_account = _cache.GetOrCreate($"account:{_account.Id}", (c) =>
{
c.SetAbsoluteExpiration(TimeSpan.FromMinutes(2));

return DbHelper.AccountStore.Get(_account.Id);
});
// 必须数据库中存在
var acc = DbHelper.AccountStore.Get(_account.Id);
if (acc != null)
{
return acc;
}

return _account;
});
}
}
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to get account.");

// 不清空
//_account = null;
_logger.Error(ex, "Failed to get account. {@0}", _account?.Id ?? "unknown");
}

return _account;
Expand Down

0 comments on commit 54bfef2

Please sign in to comment.