chore: clean up unused code
This commit is contained in:
parent
db5d7bb4f8
commit
2deac26fc8
1 changed files with 1 additions and 33 deletions
|
|
@ -14,43 +14,11 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using Catalogger.Backend.Database.Redis;
|
using Catalogger.Backend.Database.Redis;
|
||||||
using Remora.Discord.API;
|
|
||||||
using Remora.Discord.API.Abstractions.Objects;
|
|
||||||
using Remora.Discord.API.Abstractions.Rest;
|
|
||||||
|
|
||||||
namespace Catalogger.Backend.Api;
|
namespace Catalogger.Backend.Api;
|
||||||
|
|
||||||
public class ApiCache(RedisService redisService, IDiscordRestChannelAPI channelApi, Config config)
|
public class ApiCache(RedisService redisService)
|
||||||
{
|
{
|
||||||
private List<IMessage>? _news;
|
|
||||||
private readonly SemaphoreSlim _newsSemaphore = new(1);
|
|
||||||
|
|
||||||
public async Task<List<IMessage>> GetNewsAsync()
|
|
||||||
{
|
|
||||||
await _newsSemaphore.WaitAsync();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_news != null)
|
|
||||||
return _news;
|
|
||||||
|
|
||||||
if (config.Web.NewsChannel == null)
|
|
||||||
return [];
|
|
||||||
|
|
||||||
var res = await channelApi.GetChannelMessagesAsync(
|
|
||||||
DiscordSnowflake.New(config.Web.NewsChannel.Value),
|
|
||||||
limit: 5
|
|
||||||
);
|
|
||||||
if (res.IsSuccess)
|
|
||||||
return _news = res.Entity.ToList();
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_newsSemaphore.Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string UserKey(string id) => $"api-user:{id}";
|
private static string UserKey(string id) => $"api-user:{id}";
|
||||||
|
|
||||||
private static string GuildsKey(string userId) => $"api-user-guilds:{userId}";
|
private static string GuildsKey(string userId) => $"api-user-guilds:{userId}";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue