#!/usr/bin/env python3
import sqlite3, time, sys

db_path = sys.argv[1] if len(sys.argv) > 1 else '/root/search.db'
conn = sqlite3.connect(db_path)
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA busy_timeout=120000")
t0 = time.time()
print(f'Starting FTS rebuild for {db_path} at {time.strftime("%H:%M:%S")}...')
sys.stdout.flush()
conn.execute("INSERT INTO gov_search(gov_search) VALUES('rebuild')")
conn.commit()
elapsed = time.time() - t0
count = conn.execute('SELECT count(*) FROM gov_search').fetchone()[0]
print(f'Done in {elapsed:.0f}s. FTS rows: {count}')
conn.close()
