Added .nsfwcc command to prevent memory leaks if nsfw is spammed a lot.

This commit is contained in:
Master Kwoth 2017-09-11 19:30:02 +02:00
parent cdf15d6c01
commit 81a7c6f398
4 changed files with 31 additions and 0 deletions

View File

@ -206,6 +206,15 @@ namespace NadekoBot.Modules.NSFW
} }
} }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly]
public Task NsfwClearCache()
{
_service.ClearCache();
return Context.Channel.SendConfirmAsync("👌");
}
public async Task InternalDapiCommand(string tag, DapiSearchType type, bool forceExplicit) public async Task InternalDapiCommand(string tag, DapiSearchType type, bool forceExplicit)
{ {
ImageCacherObject imgObj; ImageCacherObject imgObj;

View File

@ -165,6 +165,11 @@ namespace NadekoBot.Modules.Searches.Common
} }
return list.ToArray(); return list.ToArray();
} }
public void Clear()
{
_cache.Clear();
}
} }
public class ImageCacherObject : IComparable<ImageCacherObject> public class ImageCacherObject : IComparable<ImageCacherObject>

View File

@ -187,6 +187,14 @@ namespace NadekoBot.Modules.Searches.Services
} }
return added; return added;
} }
public void ClearCache()
{
foreach (var c in _imageCacher)
{
c.Value?.Clear();
}
}
} }
public struct UserChannelPair public struct UserChannelPair

View File

@ -3771,4 +3771,13 @@
<data name="clubleaderboard_desc" xml:space="preserve"> <data name="clubleaderboard_desc" xml:space="preserve">
<value>Shows club rankings on the specified page.</value> <value>Shows club rankings on the specified page.</value>
</data> </data>
<data name="nsfwclearcache_cmd" xml:space="preserve">
<value>nsfwcc</value>
</data>
<data name="nsfwclearcache_usage" xml:space="preserve">
<value>`{0}nsfwcc`</value>
</data>
<data name="nsfwclearcache_desc" xml:space="preserve">
<value>Clears nsfw cache.</value>
</data>
</root> </root>