summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2016-04-08 18:55:38 +0100
committerMatthew Hodgson <matthew@matrix.org>2016-04-08 18:55:38 +0100
commitfb83f6a1fcb8125ee1ddca81269b3593c727e84d (patch)
treea810a521c68428aaa0e00f3439d87690613d5856 /synapse/storage
parentAdd more doc (diff)
downloadsynapse-fb83f6a1fcb8125ee1ddca81269b3593c727e84d.tar.xz
fix SQL based on PR feedback
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/media_repository.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/synapse/storage/media_repository.py b/synapse/storage/media_repository.py
index c9dd20eed8..6bc53bbb6d 100644
--- a/synapse/storage/media_repository.py
+++ b/synapse/storage/media_repository.py
@@ -58,9 +58,10 @@ class MediaRepositoryStore(SQLBaseStore):
         def get_url_cache_txn(txn):
             # get the most recently cached result (relative to the given ts)
             sql = (
-                "SELECT response_code, etag, expires, og, media_id, max(download_ts)"
+                "SELECT response_code, etag, expires, og, media_id, download_ts"
                 " FROM local_media_repository_url_cache"
                 " WHERE url = ? AND download_ts <= ?"
+                " ORDER BY download_ts DESC LIMIT 1"
             )
             txn.execute(sql, (url, ts))
             row = txn.fetchone()
@@ -69,9 +70,10 @@ class MediaRepositoryStore(SQLBaseStore):
                 # ...or if we've requested a timestamp older than the oldest
                 # copy in the cache, return the oldest copy (if any)
                 sql = (
-                    "SELECT response_code, etag, expires, og, media_id, min(download_ts)"
+                    "SELECT response_code, etag, expires, og, media_id, download_ts"
                     " FROM local_media_repository_url_cache"
                     " WHERE url = ? AND download_ts > ?"
+                    " ORDER BY download_ts ASC LIMIT 1"
                 )
                 txn.execute(sql, (url, ts))
                 row = txn.fetchone()