Ticket #11569: cache_db_upsert.patch

File cache_db_upsert.patch, 1.5 KB (added by gerdemb, 13 years ago)

Patch to Django 1.3 to fix cache database backend from inserting duplicated cache_keys

Line 
1*** /usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/cache/backends/db.py 2011-04-07 22:21:18.508030076 +0200
2--- db.py 2011-10-21 21:20:41.329180165 +0200
3***************
4*** 88,95 ****
5 cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table,
6 [encoded, connections[db].ops.value_to_db_datetime(exp), key])
7 else:
8! cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table,
9! [key, encoded, connections[db].ops.value_to_db_datetime(exp)])
10 except DatabaseError:
11 # To be threadsafe, updates/inserts are allowed to fail silently
12 transaction.rollback_unless_managed(using=db)
13--- 88,95 ----
14 cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table,
15 [encoded, connections[db].ops.value_to_db_datetime(exp), key])
16 else:
17! cursor.execute("INSERT INTO %s (cache_key, value, expires) SELECT %%s, %%s, %%s WHERE NOT EXISTS (SELECT 1 FROM %s WHERE cache_key = %%s)" % (table, table),
18! [key, encoded, connections[db].ops.value_to_db_datetime(exp), key])
19 except DatabaseError:
20 # To be threadsafe, updates/inserts are allowed to fail silently
21 transaction.rollback_unless_managed(using=db)
Back to Top