Optimize list API payloads and replace homepage swiper with a lighter slider.
Skip unused HTML and metadata from client/admin list queries so pages load less data, and load banner detail by id. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,24 +34,27 @@ func (r repository) GetAllData(ctx context.Context, params listing.Params) (news
|
||||
var dt news.DataNewsDTO
|
||||
|
||||
where := ""
|
||||
join := ""
|
||||
args := []interface{}{}
|
||||
if params.Search != "" {
|
||||
// JOIN only for search filter; list still skips large HTML bodies.
|
||||
join = ` LEFT JOIN news_content nc ON n.id = nc.news_id `
|
||||
where = ` WHERE n.title::text ILIKE $1 OR nc.tm ILIKE $1 OR nc.ru ILIKE $1 OR nc.en ILIKE $1 `
|
||||
args = append(args, params.SearchPattern())
|
||||
}
|
||||
|
||||
qC := `SELECT count(*) FROM news n LEFT JOIN news_content nc ON n.id = nc.news_id` + where + `;`
|
||||
qC := `SELECT count(*) FROM news n` + join + where + `;`
|
||||
if err := r.client.QueryRow(ctx, qC, args...).Scan(&dt.Count); err != nil {
|
||||
r.logger.Error("count news :::", err)
|
||||
return dt, err
|
||||
}
|
||||
|
||||
// List endpoint: skip news_content body. Full HTML is loaded via GetOneData.
|
||||
q := ` SELECT
|
||||
n.id, n.title,
|
||||
n.date_release, n.img,
|
||||
nc.en, nc.tm, nc.ru
|
||||
FROM news n
|
||||
LEFT JOIN news_content nc ON n.id = nc.news_id ` +
|
||||
n.date_release, n.img
|
||||
FROM news n` +
|
||||
join +
|
||||
where +
|
||||
params.OrderClause(sortColumns, "n.date_release DESC")
|
||||
|
||||
@@ -78,8 +81,6 @@ func (r repository) GetAllData(ctx context.Context, params listing.Params) (news
|
||||
if err = rows.Scan(
|
||||
&n.Id, &n.Title,
|
||||
&n.DataRelease, &n.Image,
|
||||
&n.Content.En,
|
||||
&n.Content.Tm, &n.Content.Ru,
|
||||
); err != nil {
|
||||
r.logger.Error("scan news :::", err)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user