Skip to content

Commit

Permalink
Update and Patch
Browse files Browse the repository at this point in the history
Better sync fts
Added Log Print into FTS Initializer
Patch: update Virtual Table after user add data to the root table
  • Loading branch information
EndermanPC committed Feb 10, 2024
1 parent 25bca14 commit 64bc7a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions FTS/initializer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sqlite3

from log.write import sys_log

def Initializer_Virtual_Table():
conn = sqlite3.connect('./database/search-index.db')

conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts
USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''')

conn.close()

sys_log("Initializer Virtual Table", "search-index.db")
6 changes: 3 additions & 3 deletions FTS/update.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sqlite3

def Update_Virtual_Table():
conn = sqlite3.connect('./database/search-index.db')
from log.write import sys_log

def Update_Virtual_Table(conn):
conn.execute('DELETE FROM information_fts')
conn.execute('''INSERT INTO information_fts(site_id, link, title, text, description, keywords, shorttext, added)
SELECT site_id, link, title, text, description, keywords, shorttext, added FROM information''')

conn.commit()

conn.close()
sys_log("Update Virtual Table", "search-index.db")
6 changes: 5 additions & 1 deletion adpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from account.username import get_username
from atmt import ATMT_STRT
from initializer.database import Initializer_Database
from initializer.loader import database_loader
from log.write import log, sys_log
from account.loader import account_database_loader
from account.reliability import get_user_reliability
Expand Down Expand Up @@ -134,8 +135,11 @@ def change_reliability_by_user_id(user_id, new_reliability):
compare_databases()
elif command == "sync":
synchronization_databases()
print("Successful data synchronization.")
elif command == "sync-fts":
Update_Virtual_Table()
vt_conn = database_loader()
Update_Virtual_Table(vt_conn)
print("Successful data synchronization.")
elif command == "log":
with open('log.txt', 'r') as file:
for line in file:
Expand Down
7 changes: 7 additions & 0 deletions manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from manager.edit import edit_data
from manager.insert import insert_data
from manager.remove import remove_data
from FTS.update import Update_Virtual_Table

def manager_insert_data(conn, username, password, link, title, text, description, keywords, shorttext):
account_conn = account_database_loader()
Expand All @@ -29,6 +30,8 @@ def manager_insert_data(conn, username, password, link, title, text, description
cursor.close()
account_conn.close()

Update_Virtual_Table(conn)

def manager_edit_data(conn, username, password, site_id, link, title, text, description, keywords, shorttext):
account_conn = account_database_loader()
cursor = account_conn.cursor()
Expand All @@ -50,6 +53,8 @@ def manager_edit_data(conn, username, password, site_id, link, title, text, desc
cursor.close()
account_conn.close()

Update_Virtual_Table(conn)

def manager_remove_data(conn, username, password, site_id):
account_conn = account_database_loader()
cursor = account_conn.cursor()
Expand All @@ -66,3 +71,5 @@ def manager_remove_data(conn, username, password, site_id):

account_conn.close()
cursor.close()

Update_Virtual_Table(conn)

0 comments on commit 64bc7a7

Please sign in to comment.