minetest / contentdb

A content database for Minetest mods, games, and more
https://content.minetest.net
GNU Affero General Public License v3.0
94 stars 46 forks source link

Improve packages query speed #271

Closed rubenwardy closed 3 years ago

rubenwardy commented 3 years ago

Currently, a big query is ran to find packages that match some filters and a sort order. Then for each package, two queries are executed to find the screenshot and release.

This means there are 2*n + 1 queries which run in sequence, which results in a 10 second page load time.

Tables

Package:
    id

PackageRelease:
    id
    package_id
    min_rel
    max_rel

PackageScreenshot:
    id
    package_id
    approved

MinetestRelease
    id

/api/packages/

In summary, the algorithm should be this:

The REST result looks a bit like this:

[
  {
    "author": "Jeija",
    "name": "mesecons",
    "release": 1771,
    "short_description": "Adds digital circuitry, including wires, buttons, lights, and even programmable controllers.",
    "thumbnail": "https://content.minetest.net/thumbnails/1/mwaTPqpj7e.png",
    "title": "Mesecons",
    "type": "mod"
  }
]
rubenwardy commented 3 years ago

https://github.com/minetest/contentdb/commit/c0112828ebf61e2fbb2588a8515ba0f6ec8b673e