소스 검색

Fix cache retrieval behavior.

tags/v1.0^2
Ben Kurtovic 10 년 전
부모
커밋
8acddb6834
1개의 변경된 파일9개의 추가작업 그리고 6개의 파일을 삭제
  1. +9
    -6
      bitshift/database/__init__.py

+ 9
- 6
bitshift/database/__init__.py 파일 보기

@@ -160,22 +160,25 @@ class Database(object):
:return: The total number of results, and the *n*\ th page of results.
:rtype: 2-tuple of (long, list of :py:class:`.Codelet`\ s)
"""
query1 = """SELECT cdata_codelet, cache_count_mnt, cache_count_exp
query1 = "SELECT 1 FROM cache WHERE cache_id = ?"
query2 = """SELECT cdata_codelet, cache_count_mnt, cache_count_exp
FROM cache
INNER JOIN cache_data ON cache_id = cdata_cache
WHERE cache_id = ?"""
query2 = "INSERT INTO cache VALUES (?, ?, ?, DEFAULT)"
query3 = "INSERT INTO cache_data VALUES (?, ?)"
query3 = "INSERT INTO cache VALUES (?, ?, ?, DEFAULT)"
query4 = "INSERT INTO cache_data VALUES (?, ?)"

cache_id = mmh3.hash64(str(page) + ":" + query.serialize())[0]

with self._conn.cursor() as cursor:
cursor.execute(query1, (cache_id,))
results = cursor.fetchall()
if results: # Cache hit
cache_hit = cursor.fetchall()
if cache_hit:
cursor.execute(query2, (cache_id,))
results = cursor.fetchall()
num_results = results[0][1] * (10 ** results[0][2])
ids = [res[0] for res in results]
else: # Cache miss
else:
ids, num_results = self._search_with_query(cursor, query, page)
num_exp = max(len(str(num_results)) - 3, 0)
num_results = int(round(num_results, -num_exp))


불러오는 중...
취소
저장