We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Organisations list gives timeout
## Test plan

The organisations list should not give a timeout. Since this only happened on Live, it is hard to debug.
## Sentry

See http://sentry.support.akvo-ops.org/rsr/live/group/742/


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `akvo/rsr/views/organisation.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 """Akvo RSR is covered by the GNU Affero General Public License.
4 
5 See more details in the license.txt file located at the root folder of the
6 Akvo RSR module. For additional details on the GNU license please
7 see < http://www.gnu.org/licenses/agpl.html >.
8 """
9 
10 from django.db.models import Prefetch
11 from django.db.models import Count
12 from django.shortcuts import get_object_or_404, render
13 
14 from ..filters import location_choices, OrganisationFilter, remove_empty_querydict_items
15 from ..models import Employment, Organisation, Project, ProjectUpdate
16 from ...utils import pagination, filter_query_string
17 from .utils import apply_keywords, org_projects, show_filter_class
18 
19 ###############################################################################
20 # Organisation directory
21 ###############################################################################
22 
23 
24 def _public_projects():
25     """Return all public projects."""
26     return Project.objects.public().published().select_related('partners').order_by('-id')
27 
28 
29 def _page_organisations(page):
30     """Dig out the list or organisations to use."""
31     projects = org_projects(page.organisation) if page.partner_projects else _public_projects()
32     keyword_projects = apply_keywords(page, projects)
33     return keyword_projects.all_partners()
34 
35 
36 def _organisation_directory_coll(request):
37     """Dig out and pass correct organisations to the view."""
38     page = request.rsr_page
39     if not page:
40         return Organisation.objects.all()
41     return _page_organisations(page)
42 
43 
44 def directory(request):
45     """The Organisation list view."""
46     qs = remove_empty_querydict_items(request.GET)
47 
48     # Set show_filters to "in" if any filter is selected
49     filter_class = show_filter_class(qs, ['location', ])
50 
51     # Yank Organisation collection
52     all_organisations = _organisation_directory_coll(request)
53 
54     # Easter egg feature
55     creator_organisations = request.GET.get('creator', False)
56     if creator_organisations:
57         all_organisations = all_organisations.filter(can_create_projects=True)
58 
59     f = OrganisationFilter(qs, queryset=all_organisations)
60 
61     # Change filter options further when on an Akvo Page
62     if request.rsr_page:
63         # Filter location filter list to only populated locations
64         f.filters['location'].extra['choices'] = location_choices(all_organisations)
65 
66     # Build page
67     page = request.GET.get('page')
68     page, paginator, page_range = pagination(page, f.qs.distinct(), 10)
69 
70     # Get organisations to be displayed on the map
71     if request.rsr_page and request.rsr_page.all_maps:
72         map_orgs = all_organisations
73     else:
74         map_orgs = page.object_list
75     map_orgs = map_orgs
76 
77     # Get related objects of page at once
78     page.object_list = page.object_list.select_related(
79         'primary_location__country',
80     ).annotate(
81         num_employees=Count('employees', distinct=True),
82         num_projects=Count('projects', distinct=True),
83         num_updates=Count('projects__project_updates', distinct=True),
84     )
85 
86     return render(request, 'organisation_directory.html', {
87         'orgs_count': f.qs.distinct().count(),
88         'filter': f,
89         'page': page,
90         'paginator': paginator,
91         'page_range': page_range,
92         'show_filters': filter_class,
93         'q': filter_query_string(qs),
94         'map_organisations': map_orgs,
95     })
96 
97 
98 ###############################################################################
99 # Organisation main
100 ###############################################################################
101 
102 
103 def main(request, organisation_id):
104     """The organisation main view."""
105     return render(request, 'organisation_main.html', {
106         'organisation': get_object_or_404(Organisation, pk=organisation_id)})
107
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/akvo/rsr/views/organisation.py b/akvo/rsr/views/organisation.py
--- a/akvo/rsr/views/organisation.py
+++ b/akvo/rsr/views/organisation.py
@@ -77,10 +77,6 @@
     # Get related objects of page at once
     page.object_list = page.object_list.select_related(
         'primary_location__country',
-    ).annotate(
-        num_employees=Count('employees', distinct=True),
-        num_projects=Count('projects', distinct=True),
-        num_updates=Count('projects__project_updates', distinct=True),
     )
 
     return render(request, 'organisation_directory.html', {

{"golden_diff": "diff --git a/akvo/rsr/views/organisation.py b/akvo/rsr/views/organisation.py\n--- a/akvo/rsr/views/organisation.py\n+++ b/akvo/rsr/views/organisation.py\n@@ -77,10 +77,6 @@\n     # Get related objects of page at once\n     page.object_list = page.object_list.select_related(\n         'primary_location__country',\n-    ).annotate(\n-        num_employees=Count('employees', distinct=True),\n-        num_projects=Count('projects', distinct=True),\n-        num_updates=Count('projects__project_updates', distinct=True),\n     )\n \n     return render(request, 'organisation_directory.html', {\n", "issue": "Organisations list gives timeout\n## Test plan\n\nThe organisations list should not give a timeout. Since this only happened on Live, it is hard to debug.\n## Sentry\n\nSee http://sentry.support.akvo-ops.org/rsr/live/group/742/\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom django.db.models import Prefetch\nfrom django.db.models import Count\nfrom django.shortcuts import get_object_or_404, render\n\nfrom ..filters import location_choices, OrganisationFilter, remove_empty_querydict_items\nfrom ..models import Employment, Organisation, Project, ProjectUpdate\nfrom ...utils import pagination, filter_query_string\nfrom .utils import apply_keywords, org_projects, show_filter_class\n\n###############################################################################\n# Organisation directory\n###############################################################################\n\n\ndef _public_projects():\n    \"\"\"Return all public projects.\"\"\"\n    return Project.objects.public().published().select_related('partners').order_by('-id')\n\n\ndef _page_organisations(page):\n    \"\"\"Dig out the list or organisations to use.\"\"\"\n    projects = org_projects(page.organisation) if page.partner_projects else _public_projects()\n    keyword_projects = apply_keywords(page, projects)\n    return keyword_projects.all_partners()\n\n\ndef _organisation_directory_coll(request):\n    \"\"\"Dig out and pass correct organisations to the view.\"\"\"\n    page = request.rsr_page\n    if not page:\n        return Organisation.objects.all()\n    return _page_organisations(page)\n\n\ndef directory(request):\n    \"\"\"The Organisation list view.\"\"\"\n    qs = remove_empty_querydict_items(request.GET)\n\n    # Set show_filters to \"in\" if any filter is selected\n    filter_class = show_filter_class(qs, ['location', ])\n\n    # Yank Organisation collection\n    all_organisations = _organisation_directory_coll(request)\n\n    # Easter egg feature\n    creator_organisations = request.GET.get('creator', False)\n    if creator_organisations:\n        all_organisations = all_organisations.filter(can_create_projects=True)\n\n    f = OrganisationFilter(qs, queryset=all_organisations)\n\n    # Change filter options further when on an Akvo Page\n    if request.rsr_page:\n        # Filter location filter list to only populated locations\n        f.filters['location'].extra['choices'] = location_choices(all_organisations)\n\n    # Build page\n    page = request.GET.get('page')\n    page, paginator, page_range = pagination(page, f.qs.distinct(), 10)\n\n    # Get organisations to be displayed on the map\n    if request.rsr_page and request.rsr_page.all_maps:\n        map_orgs = all_organisations\n    else:\n        map_orgs = page.object_list\n    map_orgs = map_orgs\n\n    # Get related objects of page at once\n    page.object_list = page.object_list.select_related(\n        'primary_location__country',\n    ).annotate(\n        num_employees=Count('employees', distinct=True),\n        num_projects=Count('projects', distinct=True),\n        num_updates=Count('projects__project_updates', distinct=True),\n    )\n\n    return render(request, 'organisation_directory.html', {\n        'orgs_count': f.qs.distinct().count(),\n        'filter': f,\n        'page': page,\n        'paginator': paginator,\n        'page_range': page_range,\n        'show_filters': filter_class,\n        'q': filter_query_string(qs),\n        'map_organisations': map_orgs,\n    })\n\n\n###############################################################################\n# Organisation main\n###############################################################################\n\n\ndef main(request, organisation_id):\n    \"\"\"The organisation main view.\"\"\"\n    return render(request, 'organisation_main.html', {\n        'organisation': get_object_or_404(Organisation, pk=organisation_id)})\n", "path": "akvo/rsr/views/organisation.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom django.db.models import Prefetch\nfrom django.db.models import Count\nfrom django.shortcuts import get_object_or_404, render\n\nfrom ..filters import location_choices, OrganisationFilter, remove_empty_querydict_items\nfrom ..models import Employment, Organisation, Project, ProjectUpdate\nfrom ...utils import pagination, filter_query_string\nfrom .utils import apply_keywords, org_projects, show_filter_class\n\n###############################################################################\n# Organisation directory\n###############################################################################\n\n\ndef _public_projects():\n    \"\"\"Return all public projects.\"\"\"\n    return Project.objects.public().published().select_related('partners').order_by('-id')\n\n\ndef _page_organisations(page):\n    \"\"\"Dig out the list or organisations to use.\"\"\"\n    projects = org_projects(page.organisation) if page.partner_projects else _public_projects()\n    keyword_projects = apply_keywords(page, projects)\n    return keyword_projects.all_partners()\n\n\ndef _organisation_directory_coll(request):\n    \"\"\"Dig out and pass correct organisations to the view.\"\"\"\n    page = request.rsr_page\n    if not page:\n        return Organisation.objects.all()\n    return _page_organisations(page)\n\n\ndef directory(request):\n    \"\"\"The Organisation list view.\"\"\"\n    qs = remove_empty_querydict_items(request.GET)\n\n    # Set show_filters to \"in\" if any filter is selected\n    filter_class = show_filter_class(qs, ['location', ])\n\n    # Yank Organisation collection\n    all_organisations = _organisation_directory_coll(request)\n\n    # Easter egg feature\n    creator_organisations = request.GET.get('creator', False)\n    if creator_organisations:\n        all_organisations = all_organisations.filter(can_create_projects=True)\n\n    f = OrganisationFilter(qs, queryset=all_organisations)\n\n    # Change filter options further when on an Akvo Page\n    if request.rsr_page:\n        # Filter location filter list to only populated locations\n        f.filters['location'].extra['choices'] = location_choices(all_organisations)\n\n    # Build page\n    page = request.GET.get('page')\n    page, paginator, page_range = pagination(page, f.qs.distinct(), 10)\n\n    # Get organisations to be displayed on the map\n    if request.rsr_page and request.rsr_page.all_maps:\n        map_orgs = all_organisations\n    else:\n        map_orgs = page.object_list\n    map_orgs = map_orgs\n\n    # Get related objects of page at once\n    page.object_list = page.object_list.select_related(\n        'primary_location__country',\n    )\n\n    return render(request, 'organisation_directory.html', {\n        'orgs_count': f.qs.distinct().count(),\n        'filter': f,\n        'page': page,\n        'paginator': paginator,\n        'page_range': page_range,\n        'show_filters': filter_class,\n        'q': filter_query_string(qs),\n        'map_organisations': map_orgs,\n    })\n\n\n###############################################################################\n# Organisation main\n###############################################################################\n\n\ndef main(request, organisation_id):\n    \"\"\"The organisation main view.\"\"\"\n    return render(request, 'organisation_main.html', {\n        'organisation': get_object_or_404(Organisation, pk=organisation_id)})\n", "path": "akvo/rsr/views/organisation.py"}]}