prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Gunicorn consuming excessive amounts of memory
  **Version**
  3.16.z
  
  **Describe the bug**
  Gunicorn consuming excessive amounts of memory, 3.5-4gb
  
  **To Reproduce**
  Unclear
  
  **Expected behavior**
  Probably not to have a single gunicorn process use 4gb of memory
  
  **Additional context**
  
  BZ: https://bugzilla.redhat.com/show_bug.cgi?id=2035873
  Katello forum discussion: https://community.theforeman.org/t/katello-4-5-foreman-3-3-memory-leak-in-gunicorn/29658/22
  
  </issue>
  <code>
  [start of pulpcore/app/access_policy.py]
  1 from functools import lru_cache
  2 from rest_access_policy import AccessPolicy
  3 from rest_framework.exceptions import APIException
  4 
  5 from pulpcore.app.models import AccessPolicy as AccessPolicyModel
  6 from pulpcore.app.util import get_view_urlpattern, get_viewset_for_model
  7 
  8 
  9 class AccessPolicyFromDB(AccessPolicy):
  10     """
  11     An AccessPolicy that loads statements from an `AccessPolicy` model instance.
  12     """
  13 
  14     @staticmethod
  15     @lru_cache
  16     def get_access_policy(view):
  17         """
  18         Retrieves the AccessPolicy from the DB or None if it doesn't exist.
  19 
  20         Args:
  21             view (subclass of rest_framework.view.APIView): The view or viewset to receive the
  22                 AccessPolicy model for.
  23 
  24         Returns:
  25             Either a `pulpcore.app.models.AccessPolicy` or None.
  26         """
  27         try:
  28             urlpattern = get_view_urlpattern(view)
  29         except AttributeError:
  30             # The view does not define a `urlpattern()` method, e.g. it's not a NamedModelViewset
  31             return None
  32 
  33         try:
  34             return AccessPolicyModel.objects.get(viewset_name=urlpattern)
  35         except AccessPolicyModel.DoesNotExist:
  36             return None
  37 
  38     @classmethod
  39     def handle_creation_hooks(cls, obj):
  40         """
  41         Handle the creation hooks defined in this policy for the passed in `obj`.
  42 
  43         Args:
  44             cls: The class this method belongs to.
  45             obj: The model instance to have its creation hooks handled for.
  46 
  47         """
  48         viewset = get_viewset_for_model(obj)
  49         access_policy = cls.get_access_policy(viewset)
  50         if access_policy and access_policy.creation_hooks is not None:
  51             for creation_hook in access_policy.creation_hooks:
  52                 hook_name = creation_hook["function"]
  53                 try:
  54                     function = obj.REGISTERED_CREATION_HOOKS[hook_name]
  55                 except KeyError:
  56                     raise APIException(
  57                         f"Creation hook '{hook_name}' was not registered for this view set."
  58                     )
  59 
  60                 kwargs = creation_hook.get("parameters") or {}
  61                 function(**kwargs)
  62 
  63     def scope_queryset(self, view, qs):
  64         """
  65         Scope the queryset based on the access policy `scope_queryset` method if present.
  66         """
  67         if access_policy := self.get_access_policy(view):
  68             if access_policy.queryset_scoping:
  69                 scope = access_policy.queryset_scoping["function"]
  70                 if not (function := getattr(view, scope, None)):
  71                     raise APIException(
  72                         f"Queryset scoping method {scope} is not present on this view set."
  73                     )
  74                 kwargs = access_policy.queryset_scoping.get("parameters") or {}
  75                 qs = function(qs, **kwargs)
  76         return qs
  77 
  78     def get_policy_statements(self, request, view):
  79         """
  80         Return the policy statements from an AccessPolicy instance matching the viewset name.
  81 
  82         This is an implementation of a method that will be called by
  83         `rest_access_policy.AccessPolicy`. See the drf-access-policy docs for more info:
  84 
  85         https://rsinger86.github.io/drf-access-policy/loading_external_source/
  86 
  87         The `pulpcore.plugin.models.AccessPolicy` instance is looked up by the `viewset_name`
  88         attribute using::
  89 
  90             AccessPolicyModel.objects.get(viewset_name=get_view_urlpattern(view))
  91 
  92         If a matching `pulpcore.plugin.models.AccessPolicy` cannot be found, a default behavior of
  93         allowing only admin users to perform any operation is used. This fallback allows the Pulp
  94         RBAC implementation to be turned on endpoint-by-endpoint with less effort.
  95 
  96         Args:
  97             request (rest_framework.request.Request): The request being checked for authorization.
  98             view (subclass rest_framework.viewsets.GenericViewSet): The view name being requested.
  99 
  100         Returns:
  101             The access policy statements in drf-access-policy policy structure.
  102         """
  103         if access_policy_obj := self.get_access_policy(view):
  104             return access_policy_obj.statements
  105         else:
  106             default_statement = [{"action": "*", "principal": "admin", "effect": "allow"}]
  107             policy = getattr(view, "DEFAULT_ACCESS_POLICY", {"statements": default_statement})
  108             return policy["statements"]
  109
  [end of pulpcore/app/access_policy.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pulpcore/app/access_policy.py b/pulpcore/app/access_policy.py
  --- a/pulpcore/app/access_policy.py
  +++ b/pulpcore/app/access_policy.py
  @@ -1,4 +1,3 @@
  -from functools import lru_cache
   from rest_access_policy import AccessPolicy
   from rest_framework.exceptions import APIException
   
  @@ -12,7 +11,6 @@
       """
   
       @staticmethod
  -    @lru_cache
       def get_access_policy(view):
           """
           Retrieves the AccessPolicy from the DB or None if it doesn't exist.
  
verification_info: {"golden_diff": "diff --git a/pulpcore/app/access_policy.py b/pulpcore/app/access_policy.py\n--- a/pulpcore/app/access_policy.py\n+++ b/pulpcore/app/access_policy.py\n@@ -1,4 +1,3 @@\n-from functools import lru_cache\n from rest_access_policy import AccessPolicy\n from rest_framework.exceptions import APIException\n \n@@ -12,7 +11,6 @@\n     \"\"\"\n \n     @staticmethod\n-    @lru_cache\n     def get_access_policy(view):\n         \"\"\"\n         Retrieves the AccessPolicy from the DB or None if it doesn't exist.\n", "issue": "Gunicorn consuming excessive amounts of memory\n**Version**\r\n3.16.z\r\n\r\n**Describe the bug**\r\nGunicorn consuming excessive amounts of memory, 3.5-4gb\r\n\r\n**To Reproduce**\r\nUnclear\r\n\r\n**Expected behavior**\r\nProbably not to have a single gunicorn process use 4gb of memory\r\n\r\n**Additional context**\r\n\r\nBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2035873\r\nKatello forum discussion: https://community.theforeman.org/t/katello-4-5-foreman-3-3-memory-leak-in-gunicorn/29658/22\n", "before_files": [{"content": "from functools import lru_cache\nfrom rest_access_policy import AccessPolicy\nfrom rest_framework.exceptions import APIException\n\nfrom pulpcore.app.models import AccessPolicy as AccessPolicyModel\nfrom pulpcore.app.util import get_view_urlpattern, get_viewset_for_model\n\n\nclass AccessPolicyFromDB(AccessPolicy):\n    \"\"\"\n    An AccessPolicy that loads statements from an `AccessPolicy` model instance.\n    \"\"\"\n\n    @staticmethod\n    @lru_cache\n    def get_access_policy(view):\n        \"\"\"\n        Retrieves the AccessPolicy from the DB or None if it doesn't exist.\n\n        Args:\n            view (subclass of rest_framework.view.APIView): The view or viewset to receive the\n                AccessPolicy model for.\n\n        Returns:\n            Either a `pulpcore.app.models.AccessPolicy` or None.\n        \"\"\"\n        try:\n            urlpattern = get_view_urlpattern(view)\n        except AttributeError:\n            # The view does not define a `urlpattern()` method, e.g. it's not a NamedModelViewset\n            return None\n\n        try:\n            return AccessPolicyModel.objects.get(viewset_name=urlpattern)\n        except AccessPolicyModel.DoesNotExist:\n            return None\n\n    @classmethod\n    def handle_creation_hooks(cls, obj):\n        \"\"\"\n        Handle the creation hooks defined in this policy for the passed in `obj`.\n\n        Args:\n            cls: The class this method belongs to.\n            obj: The model instance to have its creation hooks handled for.\n\n        \"\"\"\n        viewset = get_viewset_for_model(obj)\n        access_policy = cls.get_access_policy(viewset)\n        if access_policy and access_policy.creation_hooks is not None:\n            for creation_hook in access_policy.creation_hooks:\n                hook_name = creation_hook[\"function\"]\n                try:\n                    function = obj.REGISTERED_CREATION_HOOKS[hook_name]\n                except KeyError:\n                    raise APIException(\n                        f\"Creation hook '{hook_name}' was not registered for this view set.\"\n                    )\n\n                kwargs = creation_hook.get(\"parameters\") or {}\n                function(**kwargs)\n\n    def scope_queryset(self, view, qs):\n        \"\"\"\n        Scope the queryset based on the access policy `scope_queryset` method if present.\n        \"\"\"\n        if access_policy := self.get_access_policy(view):\n            if access_policy.queryset_scoping:\n                scope = access_policy.queryset_scoping[\"function\"]\n                if not (function := getattr(view, scope, None)):\n                    raise APIException(\n                        f\"Queryset scoping method {scope} is not present on this view set.\"\n                    )\n                kwargs = access_policy.queryset_scoping.get(\"parameters\") or {}\n                qs = function(qs, **kwargs)\n        return qs\n\n    def get_policy_statements(self, request, view):\n        \"\"\"\n        Return the policy statements from an AccessPolicy instance matching the viewset name.\n\n        This is an implementation of a method that will be called by\n        `rest_access_policy.AccessPolicy`. See the drf-access-policy docs for more info:\n\n        https://rsinger86.github.io/drf-access-policy/loading_external_source/\n\n        The `pulpcore.plugin.models.AccessPolicy` instance is looked up by the `viewset_name`\n        attribute using::\n\n            AccessPolicyModel.objects.get(viewset_name=get_view_urlpattern(view))\n\n        If a matching `pulpcore.plugin.models.AccessPolicy` cannot be found, a default behavior of\n        allowing only admin users to perform any operation is used. This fallback allows the Pulp\n        RBAC implementation to be turned on endpoint-by-endpoint with less effort.\n\n        Args:\n            request (rest_framework.request.Request): The request being checked for authorization.\n            view (subclass rest_framework.viewsets.GenericViewSet): The view name being requested.\n\n        Returns:\n            The access policy statements in drf-access-policy policy structure.\n        \"\"\"\n        if access_policy_obj := self.get_access_policy(view):\n            return access_policy_obj.statements\n        else:\n            default_statement = [{\"action\": \"*\", \"principal\": \"admin\", \"effect\": \"allow\"}]\n            policy = getattr(view, \"DEFAULT_ACCESS_POLICY\", {\"statements\": default_statement})\n            return policy[\"statements\"]\n", "path": "pulpcore/app/access_policy.py"}]}