Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/places.py
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:51:26 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:51:26 (GMT)
commit72be60992d01ba57ca98097974eb9ba2e6cb09b2 (patch)
tree286888468eac057ac5fea9f74b1172addb79434f /places.py
parent707f90daa6d0780cb621e63d3697baaf0996dd6d (diff)
Implement simple cleanup. Drop sites older than 30 days on startup.
Diffstat (limited to 'places.py')
-rw-r--r--places.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/places.py b/places.py
index 35e2dc0..2850dee 100644
--- a/places.py
+++ b/places.py
@@ -16,7 +16,7 @@
import os
import sqlite3
-from datetime import datetime
+from datetime import datetime, timedelta
from sugar.activity import activity
@@ -31,6 +31,9 @@ class Place(object):
self.last_visit = datetime.now()
class SqliteStore(object):
+ MAX_SEARCH_MATCHES = 20
+ EXPIRE_DAYS = 30
+
def __init__(self):
db_path = os.path.join(activity.get_activity_root(),
'data', 'places.db')
@@ -48,13 +51,16 @@ class SqliteStore(object):
last_visit timestamp
);
""")
+ else:
+ self._cleanup()
def search(self, text):
cur = self._con.cursor()
text = '%' + text + '%'
cur.execute('select * from places where uri like ? or title like ? ' \
- 'order by visits desc limit 0, 30', (text, text))
+ 'order by visits desc limit 0, ?',
+ (text, text, self.MAX_SEARCH_MATCHES))
result = [self._place_from_row(row) for row in cur]
@@ -97,10 +103,21 @@ class SqliteStore(object):
def _place_from_row(self, row):
place = Place()
+
place.uri, place.title, place.gecko_flags, \
place.visits, place.last_visit = row
+
return place
+ def _cleanup(self):
+ cur = self._con.cursor()
+
+ date = datetime.now() - timedelta(days=self.EXPIRE_DAYS)
+ cur.execute('delete from places where last_visit < ?', (date,))
+
+ self._con.commit()
+ cur.close()
+
def get_store():
global _store
if _store == None: