Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

impl ETag to /me #2462

wants to merge 1 commit into from

Conversation

ramdos0207
Copy link

resolves #1055
キャッシュされないエンドポイントの中で最も平均のレスポンスボディが長さが長いエンドポイントである/meにETagを追加しました。これにより、リロード時の転送量の30%程度が削減できます。

https://q.trap.jp/messages/4c4ceb48-9c54-4cba-b6f4-c70224b6bfac

Copy link

@cp-20 cp-20 left a 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 {
Copy link

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())))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: ServeJSONWithEtag の実装を見ると、実は構造体をわざわざ定義しなくてもキー名でソートしてくれる気がします。が、別にどっちでも良さそう。

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/users/meでETagをつける
2 participants