Commit 40ae6d35ec494969f96e3c161491e7ae732a8a28

Thomas de Grivel 2022-02-04T19:26:06

fix sitemap

diff --git a/lib/kmxgit/organisation_manager.ex b/lib/kmxgit/organisation_manager.ex
index e3f5274..1c38550 100644
--- a/lib/kmxgit/organisation_manager.ex
+++ b/lib/kmxgit/organisation_manager.ex
@@ -9,6 +9,14 @@ defmodule Kmxgit.OrganisationManager do
   alias Kmxgit.SlugManager.Slug
   alias Kmxgit.UserManager
 
+  def list_all_organisations(params \\ %IndexParams{}) do
+    from(org in Organisation)
+    |> join(:inner, [org], s in Slug, on: s.organisation_id == org.id)
+    |> order_by([org, s], [asc_nulls_last: fragment("lower(?)", s.slug)])
+    |> preload([:owned_repositories, :slug])
+    |> Repo.all()
+  end
+
   def list_organisations(params \\ %IndexParams{}) do
     update_disk_usage()
     from(org in Organisation)
diff --git a/lib/kmxgit/user_manager.ex b/lib/kmxgit/user_manager.ex
index cd4bb51..d4d7c00 100644
--- a/lib/kmxgit/user_manager.ex
+++ b/lib/kmxgit/user_manager.ex
@@ -15,7 +15,7 @@ defmodule Kmxgit.UserManager do
     from(u in User)
     |> join(:inner, [u], s in Slug, on: s.user_id == u.id)
     |> order_by([u, s], fragment("lower(?)", s.slug))
-    |> preload(:slug)
+    |> preload([:owned_repositories, :slug])
     |> Repo.all()
   end
 
diff --git a/lib/kmxgit_web/controllers/page_controller.ex b/lib/kmxgit_web/controllers/page_controller.ex
index 120ed7b..b81d90f 100644
--- a/lib/kmxgit_web/controllers/page_controller.ex
+++ b/lib/kmxgit_web/controllers/page_controller.ex
@@ -100,8 +100,8 @@ defmodule KmxgitWeb.PageController do
 
   def sitemap(conn, _params) do
     conn
-    |> assign(:orgs, OrganisationManager.list_organisations())
-    |> assign(:users, UserManager.list_users())
+    |> assign(:orgs, OrganisationManager.list_all_organisations())
+    |> assign(:users, UserManager.list_all_users())
     |> put_resp_content_type("text/plain")
     |> render("sitemap.txt")
   end