bs-community / blessing-skin-server

Web application brings your custom skins back in offline Minecraft servers.
MIT License
815 stars 119 forks source link

皮肤库列表的性能问题 #614

Open tnqzh123 opened 5 months ago

tnqzh123 commented 5 months ago

Blessing Skin 版本

866e182 @ dev branch

PHP 版本

8.1

出现问题时所使用的浏览器

Microsoft Edge

您正在使用的 Web Server

Nginx

您正在使用宝塔吗?

出现了什么问题?

随着 users 表和 textures 表数据的增多,/skinlib/list 的响应速度越来越慢。

根据我对目前国内较大的几个皮肤站的观察(均为国内服务器),在 TTFB 不计算 DNS 查询时间、TCP 握手时间和 SSL 握手的时间的情况下:

通过观察可以得出,/skinlib/list 的 TTFB 时间与皮肤站所拥有的用户数量及材质数量成正比。

打开 APP_DEBUG 后通过 Debug Bar 发现请求一次 /skinlib/list 一共执行了两条 SQL:

select count(*) as aggregate from "textures" inner join "users" on "uid" = "uploader" where "type" in ('steve', 'alex') and "public" = 1
select "tid", "name", "type", "uploader", "public", "likes", "nickname" from "textures" inner join "users" on "uid" = "uploader" where "type" in ('steve', 'alex') and "public" = 1 order by "upload_at" desc limit 20 offset 0

在 users 表和 textures 表较大的情况下,执行第一条 SQL 的耗时远超第二条。

错误日志

No response

重现步骤

见上方问题描述