Repository: DDMAL/CantusDB

Issue:
`/index` pages take a long time to load and sometimes stall
See, for example, https://cantusdatabase.org/index/?source=123627.

Users, including Debra, have experienced long load times and stalled rendering of the full index.


Discussion:
hm... opening this myself several times, load times for the page are always ~2s. Not sure whether the ComputeCanada VM was having a bad day or something that day, but in any case, it would be better if the page loaded faster than it does.

Maybe this is a place to experiment with asynchronous loading - we could load chants in batches and display them once they've loaded, and display a loading icon while waiting for the first batch to be fetched.
FYI, it took 13s for me just now...
I've found really sketchy loading times with Compute Canada, particularly with Ubuntu. I've been in touch with them and they basically said "it's working fine." There *may* be an issue with the type of virtual HD device driver they're using?

I've switched to Fedora for our experimental Linked Data machine on the allocation, since it seems to make a difference. I've switched to FreeBSD for DIAMM, and the difference is night-and-day, but again, I don't know why.

So YMMV, but I'm suspecting possibly a weird configuration interaction between Ubuntu and the OpenStack Volumes. 
Interesting...so we may wait on doing more with this until we've done the CantusDB OS update...
It's anecdotal, but for SFTP uploads of DIAMM images on Ubuntu, we were generally seeing ~2-300kbps. Switching to FreeBSD, we're seeing ~5-8mbps. The only thing that changed is the underlying OS / Filesystem. (Data centers or upload locations stayed the same; it's still using an OpenStack Cinder Volume on Arbutus.)



Resolving patch:
diff --git a/django/cantusdb_project/main_app/views/chant.py b/django/cantusdb_project/main_app/views/chant.py
--- a/django/cantusdb_project/main_app/views/chant.py
+++ b/django/cantusdb_project/main_app/views/chant.py
@@ -1047,40 +1047,6 @@ def get_success_url(self):
         return reverse("source-edit-chants", args=[self.object.source.id])
 
 
-class ChantInventoryView(TemplateView):
-    template_name = "full_inventory.html"
-    pk_url_kwarg = "source_id"
-
-    def get_context_data(self, **kwargs):
-        context = super().get_context_data(**kwargs)
-
-        source_id = self.kwargs.get(self.pk_url_kwarg)
-        source = get_object_or_404(Source, id=source_id)
-
-        display_unpublished = self.request.user.is_authenticated
-        if (not display_unpublished) and (source.published == False):
-            raise PermissionDenied
-
-        # 4064 is the id for the sequence database
-        if source.segment.id == 4064:
-            queryset = (
-                source.sequence_set.annotate(record_type=Value("sequence"))
-                .order_by("s_sequence")
-                .select_related("genre")
-            )
-        else:
-            queryset = (
-                source.chant_set.annotate(record_type=Value("chant"))
-                .order_by("folio", "c_sequence")
-                .select_related("feast", "office", "genre", "diff_db")
-            )
-
-        context["source"] = source
-        context["chants"] = queryset
-
-        return context
-
-
 class SourceEditChantsView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
     template_name = "chant_edit.html"
     model = Chant
diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py
--- a/django/cantusdb_project/main_app/views/source.py
+++ b/django/cantusdb_project/main_app/views/source.py
@@ -328,7 +328,7 @@ def get_context_data(self, **kwargs):
             queryset = (
                 source.chant_set.annotate(record_type=Value("chant"))
                 .order_by("folio", "c_sequence")
-                .select_related("feast", "office", "genre")
+                .select_related("feast", "office", "genre", "diff_db")
             )
 
         context["source"] = source


Test patch: