Compare commits

..

4 commits

Author SHA1 Message Date
Simon Bruder 35230b6c37
flake: Update pre-commit-hooks.nix to new name
All checks were successful
/ build (push) Successful in 33s
This also removes all input overrides.
2024-07-24 12:19:59 +02:00
Simon Bruder faeec629a0
CI: Only gate OCI image push on branch 2024-07-24 12:19:58 +02:00
Simon Bruder 27ebe5770a
Remove home link from navbar
There is nothing there and it can also be reached by clicking on the
branding.
2024-07-24 12:19:58 +02:00
Simon Bruder e83bc8316e
Move away from models and manage subpackage
This architecture was started when the project still used Diesel.
Now that it uses SQLx, less things are done in Rust and more are done in
SQL. This commit now moves more of the query logic into SQL, which
should lead to more efficient queries and less moving data around.
2024-07-24 12:19:55 +02:00
2 changed files with 10 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "\n WITH RECURSIVE cte AS (\n SELECT\n id,\n ARRAY[]::UUID[] AS parents,\n ARRAY[]::VARCHAR[] AS parent_names,\n ARRAY[]::VARCHAR[] AS parent_class_names\n FROM items\n WHERE parent IS NULL\n\n UNION\n\n SELECT\n items.id,\n cte.parents || items.parent,\n cte.parent_names || items.name,\n cte.parent_class_names || item_classes.name\n FROM items\n JOIN cte\n ON items.parent = cte.id\n JOIN item_classes\n ON items.class = item_classes.id\n )\n SELECT\n cte.id AS \"id!\",\n items.name,\n items.class,\n item_classes.name AS \"class_name\",\n cte.parents AS \"parents!\",\n cte.parent_names AS \"parent_names!: Vec<Option<String>>\",\n cte.parent_class_names AS \"parent_class_names!\"\n FROM cte\n JOIN items\n ON cte.id = items.id\n JOIN item_classes\n ON items.class = item_classes.id\n ORDER BY items.created_at\n ", "query": "\n WITH RECURSIVE cte AS (\n SELECT\n id,\n ARRAY[]::UUID[] AS parents,\n ARRAY[]::VARCHAR[] AS parent_names,\n ARRAY[]::VARCHAR[] AS parent_class_names\n FROM items\n WHERE parent IS NULL\n\n UNION\n\n SELECT\n items.id,\n cte.parents || items.parent,\n cte.parent_names || parent.name,\n cte.parent_class_names || parent_class.name\n FROM cte\n JOIN items\n ON items.parent = cte.id\n JOIN items AS \"parent\"\n ON parent.id = cte.id\n JOIN item_classes AS \"parent_class\"\n ON parent.class = parent_class.id\n )\n SELECT\n cte.id AS \"id!\",\n items.name,\n items.class,\n item_classes.name AS \"class_name\",\n cte.parents AS \"parents!\",\n cte.parent_names AS \"parent_names!: Vec<Option<String>>\",\n cte.parent_class_names AS \"parent_class_names!\"\n FROM cte\n JOIN items\n ON cte.id = items.id\n JOIN item_classes\n ON items.class = item_classes.id\n ORDER BY items.created_at\n ",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -52,5 +52,5 @@
null null
] ]
}, },
"hash": "5dac9aa215abdc07cda1f4d46db4bcafec45b6264efcb8a175580a71e48c7421" "hash": "3dedb7b184103c1d418f7b94e26c75aea0c7d22e009299d1b87443e350578171"
} }

View file

@ -44,13 +44,15 @@ async fn get(pool: web::Data<PgPool>, user: Identity) -> actix_web::Result<impl
SELECT SELECT
items.id, items.id,
cte.parents || items.parent, cte.parents || items.parent,
cte.parent_names || items.name, cte.parent_names || parent.name,
cte.parent_class_names || item_classes.name cte.parent_class_names || parent_class.name
FROM items FROM cte
JOIN cte JOIN items
ON items.parent = cte.id ON items.parent = cte.id
JOIN item_classes JOIN items AS "parent"
ON items.class = item_classes.id ON parent.id = cte.id
JOIN item_classes AS "parent_class"
ON parent.class = parent_class.id
) )
SELECT SELECT
cte.id AS "id!", cte.id AS "id!",