Ticket #15580: 15580.patch

File 15580.patch, 2.5 KB (added by ikelly, 4 years ago)
  • django/core/cache/backends/db.py

     
    126126        if self._cull_frequency == 0:
    127127            self.clear()
    128128        else:
    129             table = connections[db].ops.quote_name(self._table)
     129            ops = connections[db].ops
     130            table = ops.quote_name(self._table)
    130131            cursor.execute("DELETE FROM %s WHERE expires < %%s" % table,
    131132                           [connections[db].ops.value_to_db_datetime(now)])
    132133            cursor.execute("SELECT COUNT(*) FROM %s" % table)
    133134            num = cursor.fetchone()[0]
    134135            if num > self._max_entries:
    135                 cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency])
     136                cursor.execute(ops.cache_key_culling_threshold() % table, [num / self._cull_frequency])
    136137                cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]])
    137138
    138139    def clear(self):
  • django/db/backends/__init__.py

     
    401401        """
    402402        return None
    403403
     404    def cache_key_culling_threshold(self):
     405        """
     406        Returns a SQL query that retrieves the first cache key greater than the
     407        n smallest.
     408       
     409        This is used by the 'db' cache backend to determine where to start
     410        culling.
     411        """
     412        return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
     413
    404414    def date_extract_sql(self, lookup_type, field_name):
    405415        """
    406416        Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
  • django/db/backends/oracle/base.py

     
    111111/""" % locals()
    112112        return sequence_sql, trigger_sql
    113113
     114    def cache_key_culling_threshold(self):
     115        return """SELECT cache_key
     116FROM (SELECT cache_key, rank() OVER (ORDER BY cache_key) AS rank FROM %s)
     117WHERE rank = %%s + 1"""
     118
    114119    def date_extract_sql(self, lookup_type, field_name):
    115120        # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions42a.htm#1017163
    116121        if lookup_type == 'week_day':
Back to Top