okashoi / isucon-practice-20200718

2 stars 0 forks source link

templateを高速化してみる #11

Open yamachu opened 4 years ago

yamachu commented 4 years ago

https://gist.github.com/catatsuy/e627aaf118fbe001f2e7c665fda48146#template%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9

template.FuncMap はテンプレート内で独自の関数を呼び出す際に必要で、移植元の参考実装が使用している場合、実装を合わせるために利用される`

FuncMapでやってるのは

url_for

src/templates/base_bottom.html:<script type="text/javascript" src="{{ url_for "/js/jquery.min.js" }}"></script>
src/templates/base_bottom.html:<script type="text/javascript" src="{{ url_for "/js/bootstrap.min.js" }}"></script>
src/templates/base_top.html:<link rel="stylesheet" href="{{ url_for "/css/bootstrap.min.css" }}">
src/templates/base_top.html:<link rel="stylesheet" href="{{ url_for "/css/bootstrap-responsive.min.css" }}">
src/templates/base_top.html:<link rel="stylesheet" href="{{ url_for "/" }}">
src/templates/base_top.html:<li><a href="{{ url_for "/" }}">Home</a></li>
src/templates/base_top.html:<li><a href="{{ url_for "/mypage" }}">MyPage</a></li>
src/templates/base_top.html:<li><a href="{{ url_for "/signin" }}">SignIn</a></li>
src/templates/index.html:  <a href="{{ url_for "/memo/" }}{{ .Id }}">{{ first_line .Content }}</a> by {{ .Username }} ({{ .CreatedAt }})
src/templates/memo.html:<a id="older" href="{{ url_for "/memo/" }}{{ .Older.Id }}">&lt; older memo</a>
src/templates/memo.html:<a id="newer" href="{{ url_for "/memo/" }}{{ .Newer.Id }}">newer memo &gt;</a>
src/templates/mypage.html:<form action="{{ url_for "/memo" }}" method="post">
src/templates/mypage.html:  <a href="{{ url_for "/memo/" }}{{ .Id }}">{{ first_line .Content }}</a> by {{ .Username }} ({{ .CreatedAt }})
src/templates/signin.html:<form action="{{ url_for "/signin" }}" method="post">

firsrt_line

src/templates/index.html:  <a href="{{ url_for "/memo/" }}{{ .Id }}">{{ first_line .Content }}</a> by {{ .Username }} ({{ .CreatedAt }})
src/templates/mypage.html:  <a href="{{ url_for "/memo/" }}{{ .Id }}">{{ first_line .Content }}</a> by {{ .Username }} ({{ .CreatedAt }})

get_token

src/templates/base_top.html:    <input type="hidden" name="sid" value="{{ get_token .Session }}">
src/templates/mypage.html:  <input type="hidden" name="sid" value="{{ get_token .Session }}">

gen_markdown

src/templates/memo.html:{{ gen_markdown .Memo.Content }}
yamachu commented 4 years ago