-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl ETag to /me #2462
base: master
Are you sure you want to change the base?
impl ETag to /me #2462
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動く実装ではあると思うんだけど、もっと良い書き方ができる気がします...!
HomeChannel optional.Of[uuid.UUID] `json:"homeChannel"` | ||
} | ||
|
||
func FormatUserInfo(ui model.UserInfo, tags []model.UserTag, groups []uuid.UUID, permissions []permission.Permission) *UserInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo: この関数を外部に公開する必要はない気がします
"permissions": h.RBAC.GetGrantedPermissions(me.GetRole()), | ||
"homeChannel": me.GetHomeChannel(), | ||
}) | ||
return extension.ServeJSONWithETag(c, FormatUserInfo(me, tags, groups, h.RBAC.GetGrantedPermissions(me.GetRole()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: ServeJSONWithEtag
の実装を見ると、実は構造体をわざわざ定義しなくてもキー名でソートしてくれる気がします。が、別にどっちでも良さそう。
traQ/router/extension/precond.go
Lines 192 to 213 in e7007b9
func ServeJSONWithETag(c echo.Context, i interface{}) error { | |
j := jsonIter.Config{ | |
EscapeHTML: false, | |
MarshalFloatWith6Digits: true, | |
ObjectFieldMustBeSimpleString: true, | |
// ここより上はjsonIter.ConfigFastestと同様 | |
SortMapKeys: true, // 順番が一致しないとEtagが一致しないのでソートを有効にする | |
}.Froze() | |
var b []byte | |
var err error | |
if _, pretty := c.QueryParams()["pretty"]; pretty { | |
b, err = j.MarshalIndent(i, "", " ") | |
} else { | |
b, err = j.Marshal(i) | |
} | |
if err != nil { | |
return err | |
} | |
return ServeWithETag(c, echo.MIMEApplicationJSON, b) | |
} |
resolves #1055
キャッシュされないエンドポイントの中で最も平均のレスポンスボディが長さが長いエンドポイントである
/me
にETagを追加しました。これにより、リロード時の転送量の30%程度が削減できます。https://q.trap.jp/messages/4c4ceb48-9c54-4cba-b6f4-c70224b6bfac