Skip to content

Commit

Permalink
feat: log cache request time
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 3, 2024
1 parent 44fda95 commit 7db7805
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \

WORKDIR /app
EXPOSE 8080
RUN apk add --update --no-cache wget libpcap icu-data-full icu-libs ca-certificates libgdiplus && \
RUN apk add --update --no-cache wget libpcap icu-data-full icu-libs ca-certificates libgdiplus tzdata && \
update-ca-certificates

COPY --from=publish /app/publish .
Expand Down
2 changes: 1 addition & 1 deletion src/GZCTF/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \

WORKDIR /app
EXPOSE 8080
RUN apk add --update --no-cache wget libpcap icu-data-full icu-libs ca-certificates libgdiplus && \
RUN apk add --update --no-cache wget libpcap icu-data-full icu-libs ca-certificates libgdiplus tzdata && \
update-ca-certificates

COPY --from=build /publish .
Expand Down
12 changes: 8 additions & 4 deletions src/GZCTF/Extensions/CacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ namespace GZCTF.Extensions;
public static class CacheExtensions
{
/// <summary>
/// 获取缓存或重新构建,如果缓存不存在会阻塞
/// 使用 CacheMaker CacheRequest 代替处理耗时更久的缓存
/// Get or create cache, if cache not exists will block
/// Use CacheMaker and CacheRequest to replace handling longer time operation
/// </summary>
public static async Task<TResult> GetOrCreateAsync<TResult, TLogger>(this IDistributedCache cache,
ILogger<TLogger> logger,
string key,
Func<DistributedCacheEntryOptions, Task<TResult>> func,
CancellationToken token = default)
{
var cacheTime = DateTimeOffset.Now;
var value = await cache.GetAsync(key, token);
TResult? result = default;

Expand All @@ -38,8 +39,11 @@ public static async Task<TResult> GetOrCreateAsync<TResult, TLogger>(this IDistr
var bytes = MemoryPackSerializer.Serialize(result);

await cache.SetAsync(key, bytes, cacheOptions, token);
logger.SystemLog(Program.StaticLocalizer[nameof(Resources.Program.Cache_Rebuilt), key, bytes.Length],
TaskStatus.Success, LogLevel.Debug);

logger.SystemLog(Program.StaticLocalizer[
nameof(Resources.Program.Cache_Updated),
key, cacheTime.ToString("HH:mm:ss.fff"), bytes.Length
], TaskStatus.Success, LogLevel.Debug);

return result;
}
Expand Down
23 changes: 12 additions & 11 deletions src/GZCTF/Resources/Program.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:schema xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -112,10 +114,12 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="Account_AvailableEmailDomain" xml:space="preserve">
<value>Available email suffix: {0}</value>
Expand Down Expand Up @@ -267,14 +271,11 @@
<data name="Cache_NoMatchingRequest" xml:space="preserve">
<value>No matching request found for cache worker: {0}</value>
</data>
<data name="Cache_Rebuilt" xml:space="preserve">
<value>Rebuild cache: {0} @ {1} bytes</value>
</data>
<data name="Cache_Stopped" xml:space="preserve">
<value>Cache update has been stopped</value>
</data>
<data name="Cache_Updated" xml:space="preserve">
<value>Cache updated: {0} @ {1} bytes</value>
<value>Cache updated: {0}[{1}] @ {2} bytes</value>
</data>
<data name="Cache_UpdateWorkerFailed" xml:space="preserve">
<value>Cache update failed: {0} @ {1}</value>
Expand Down Expand Up @@ -754,7 +755,7 @@
<value>Send mail: {0}</value>
</data>
<data name="MailSender_Template" xml:space="preserve">
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;Hello, {userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; If the above button is not valid, please copy this link to your browser: &lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;If you have not done so, please ignore this email. &lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;Hello, {userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; If the above button is not valid, please copy this link to your browser: &lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;If you have not done so, please ignore this email. &lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
</data>
<data name="MailSender_VerifyEmailButton" xml:space="preserve">
<value>Verify Email</value>
Expand Down Expand Up @@ -1033,12 +1034,12 @@
<value>Internal server error</value>
</data>
<data name="Admin_LogoUpdateFailed" xml:space="preserve">
<value>Failed to update logo</value>
<value>Failed to update logo</value>
</data>
<data name="MailSender_ConnectedToSmtp" xml:space="preserve">
<value>Successfully connected to SMTP server: {0}</value>
<value>Successfully connected to SMTP server: {0}</value>
</data>
<data name="MailSender_InvalidEmailConfig" xml:space="preserve">
<value>Invalid email configuration, but email authentication is enabled</value>
<value>Invalid email configuration, but email authentication is enabled</value>
</data>
</root>
23 changes: 12 additions & 11 deletions src/GZCTF/Resources/Program.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:schema xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -112,10 +114,12 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="Account_AvailableEmailDomain" xml:space="preserve">
<value>有効なメールドメイン:{0}</value>
Expand Down Expand Up @@ -267,14 +271,11 @@
<data name="Cache_NoMatchingRequest" xml:space="preserve">
<value>キャッシュ更新ワーカーに一致するリクエストが見つかりませんでした:{0}</value>
</data>
<data name="Cache_Rebuilt" xml:space="preserve">
<value>キャッシュが再構築されました:{0} @ {1} bytes</value>
</data>
<data name="Cache_Stopped" xml:space="preserve">
<value>キャッシュの更新が停止されました</value>
</data>
<data name="Cache_Updated" xml:space="preserve">
<value>キャッシュが更新されました:{0} @ {1} bytes</value>
<value>キャッシュが更新されました:{0}[{1}] @ {2} bytes</value>
</data>
<data name="Cache_UpdateWorkerFailed" xml:space="preserve">
<value>キャッシュ更新ワーカーが更新に失敗しました:{0} @ {1}</value>
Expand Down Expand Up @@ -754,7 +755,7 @@
<value>{0} にメールを送信します</value>
</data>
<data name="MailSender_Template" xml:space="preserve">
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;ようこそ,{userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; 上のボタンが機能しない場合は、このリンクをブラウザにコピーしてアクセスしてください:&lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;このメールに心当たりがない場合はこのメールを無視してください。&lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;ようこそ,{userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; 上のボタンが機能しない場合は、このリンクをブラウザにコピーしてアクセスしてください:&lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;このメールに心当たりがない場合はこのメールを無視してください。&lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
</data>
<data name="MailSender_VerifyEmailButton" xml:space="preserve">
<value>メールを確認する</value>
Expand Down Expand Up @@ -1033,12 +1034,12 @@
<value>サーバーで内部エラーが発生しました</value>
</data>
<data name="Admin_LogoUpdateFailed" xml:space="preserve">
<value>プラットフォームアイコンの更新に失敗しました</value>
<value>プラットフォームアイコンの更新に失敗しました</value>
</data>
<data name="MailSender_ConnectedToSmtp" xml:space="preserve">
<value>SMTPサーバーへの接続に成功しました:{0}</value>
<value>SMTPサーバーへの接続に成功しました:{0}</value>
</data>
<data name="MailSender_InvalidEmailConfig" xml:space="preserve">
<value>無効な電子メール設定ですが、電子メール認証は有効です</value>
<value>無効な電子メール設定ですが、電子メール認証は有効です</value>
</data>
</root>
23 changes: 12 additions & 11 deletions src/GZCTF/Resources/Program.resx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:schema xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -112,10 +114,12 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="Account_AvailableEmailDomain" xml:space="preserve">
<value>可用邮箱后缀:{0}</value>
Expand Down Expand Up @@ -267,14 +271,11 @@
<data name="Cache_NoMatchingRequest" xml:space="preserve">
<value>缓存更新线程未找到匹配的请求:{0}</value>
</data>
<data name="Cache_Rebuilt" xml:space="preserve">
<value>重建缓存:{0} @ {1} bytes</value>
</data>
<data name="Cache_Stopped" xml:space="preserve">
<value>缓存更新已停用</value>
</data>
<data name="Cache_Updated" xml:space="preserve">
<value>缓存已更新:{0} @ {1} bytes</value>
<value>缓存已更新:{0}[{1}] @ {2} bytes</value>
</data>
<data name="Cache_UpdateWorkerFailed" xml:space="preserve">
<value>缓存更新线程更新失败:{0} @ {1}</value>
Expand Down Expand Up @@ -754,7 +755,7 @@
<value>发送邮件:{0}</value>
</data>
<data name="MailSender_Template" xml:space="preserve">
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;你好,{userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; 如果以上按钮无效,请复制此链接到浏览器访问:&lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;如果你没有进行相关操作,请忽略此封邮件。&lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
<value>&lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"/&gt;&lt;/head&gt;&lt;body&gt;&lt;div style="max-width: 544px; margin: 0 auto; padding: 20px"&gt; &lt;h2 style="text-align: center"&gt;{title}&lt;/h2&gt; &lt;p&gt;你好,{userName}!&lt;/p&gt; &lt;p style="text-indent: 2em"&gt;{information}&lt;/p&gt; &lt;p style="text-align: center; padding: 20px"&gt; &lt;a href="{url}" style=" font: 1rem Arial; white-space: nowrap; text-decoration: none; background-color: #000000; color: #ffffff; padding: 10px 20px 10px 20px; border: 1px solid #888888; border-radius: 7px; margin: 10px auto; " &gt; {btnmsg} &lt;/a&gt; &lt;/p&gt; &lt;div style="font-size: 0.8rem"&gt; &lt;p&gt; 如果以上按钮无效,请复制此链接到浏览器访问:&lt;br/&gt;&lt;span style="word-break: break-all; font: 0.8em monospace" &gt;{url} &lt;/span&gt; &lt;/p&gt; &lt;p&gt;如果你没有进行相关操作,请忽略此封邮件。&lt;/p&gt; &lt;/div&gt; &lt;p style="font-size: 0.7em; text-align: right; color: #333"&gt;{platform} @ {nowtime}&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;</value>
</data>
<data name="MailSender_VerifyEmailButton" xml:space="preserve">
<value>确认验证邮箱</value>
Expand Down Expand Up @@ -1033,12 +1034,12 @@
<value>服务器发生内部错误</value>
</data>
<data name="Admin_LogoUpdateFailed" xml:space="preserve">
<value>平台 Logo 更新失败</value>
<value>平台 Logo 更新失败</value>
</data>
<data name="MailSender_ConnectedToSmtp" xml:space="preserve">
<value>成功连接到 SMTP 服务器:{0}</value>
<value>成功连接到 SMTP 服务器:{0}</value>
</data>
<data name="MailSender_InvalidEmailConfig" xml:space="preserve">
<value>无效的邮件配置,但邮件验证已启用</value>
<value>无效的邮件配置,但邮件验证已启用</value>
</data>
</root>
Loading

0 comments on commit 7db7805

Please sign in to comment.