database manage init
This commit is contained in:
1 parent
8724076601
commit
96e8a909d8
26 files changed
+382
-183
No files matched your search
@@ -3,6 +3,7 @@ from CodernityDB.tree_index import TreeBasedIndex
|
||||
|
||||
|
||||
class NotificationIndex(TreeBasedIndex):
|
||||
_version = 1
|
||||
|
||||
custom_header = """from CodernityDB.tree_index import TreeBasedIndex
|
||||
import time"""
|
||||
@@ -23,6 +24,7 @@ import time"""
|
||||
|
||||
|
||||
class NotificationUnreadIndex(TreeBasedIndex):
|
||||
_version = 1
|
||||
|
||||
custom_header = """from CodernityDB.tree_index import TreeBasedIndex
|
||||
import time"""
|
||||
|
||||
@@ -18,6 +18,11 @@ log = CPLog(__name__)
|
||||
|
||||
class CoreNotifier(Notification):
|
||||
|
||||
_database = {
|
||||
'notification': NotificationIndex,
|
||||
'notification_unread': NotificationUnreadIndex
|
||||
}
|
||||
|
||||
m_lock = None
|
||||
|
||||
listen_to = [
|
||||
@@ -60,28 +65,10 @@ class CoreNotifier(Notification):
|
||||
addEvent('app.load', self.clean)
|
||||
addEvent('app.load', self.checkMessages)
|
||||
|
||||
addEvent('database.setup', self.databaseSetup)
|
||||
|
||||
self.messages = []
|
||||
self.listeners = []
|
||||
self.m_lock = threading.Lock()
|
||||
|
||||
def databaseSetup(self):
|
||||
|
||||
db = get_db()
|
||||
|
||||
try:
|
||||
db.add_index(NotificationIndex(db.path, 'notification'))
|
||||
except:
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(NotificationIndex(db.path, 'notification'))
|
||||
|
||||
try:
|
||||
db.add_index(NotificationUnreadIndex(db.path, 'notification_unread'))
|
||||
except:
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(NotificationUnreadIndex(db.path, 'notification_unread'))
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
db = get_db()
|
||||
|
||||
Reference in new issue
Block a user