20250206.1738834765 diary doctor speed imporoved
This commit is contained in:
parent
0c7242d138
commit
8024771933
3 changed files with 57 additions and 19 deletions
|
@ -93,6 +93,8 @@
|
||||||
|
|
||||||
(setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
|
(setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
|
||||||
|
|
||||||
|
(setq org-log-into-drawer t)
|
||||||
|
|
||||||
(use-package! org-habit
|
(use-package! org-habit
|
||||||
:after org
|
:after org
|
||||||
:config
|
:config
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import cProfile
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pstats
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -15,6 +17,7 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -344,11 +347,15 @@ def doctor():
|
||||||
args_len = len(sys.argv)
|
args_len = len(sys.argv)
|
||||||
check_diary = False
|
check_diary = False
|
||||||
fix_diary = False
|
fix_diary = False
|
||||||
|
limit = 50
|
||||||
if args_len < 3:
|
if args_len < 3:
|
||||||
sys.exit("Usage: script.py doctor <diary_name>")
|
sys.exit("Usage: script.py doctor <diary_name>")
|
||||||
if args_len >= 4 and sys.argv[3] == "check_diary":
|
if args_len >= 4 and sys.argv[3] == "check_diary":
|
||||||
check_diary = True
|
check_diary = True
|
||||||
|
|
||||||
|
if args_len >= 5:
|
||||||
|
limit = int(sys.argv[4])
|
||||||
|
|
||||||
if args_len >= 4 and sys.argv[3] == "check_and_fix_diary":
|
if args_len >= 4 and sys.argv[3] == "check_and_fix_diary":
|
||||||
fix_diary = True
|
fix_diary = True
|
||||||
check_diary = True
|
check_diary = True
|
||||||
|
@ -364,7 +371,9 @@ def doctor():
|
||||||
initialize_db(conn)
|
initialize_db(conn)
|
||||||
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
metadata = cursor.execute("SELECT * FROM metadata").fetchall()
|
metadata = cursor.execute(
|
||||||
|
f"SELECT * FROM metadata ORDER BY id DESC LIMIT {limit}"
|
||||||
|
).fetchall()
|
||||||
for m in metadata:
|
for m in metadata:
|
||||||
weather = cursor.execute(
|
weather = cursor.execute(
|
||||||
"SELECT * FROM weather WHERE metadata_id = ?", (m[0],)
|
"SELECT * FROM weather WHERE metadata_id = ?", (m[0],)
|
||||||
|
@ -389,8 +398,13 @@ def doctor():
|
||||||
print("An empty metadata was deleted")
|
print("An empty metadata was deleted")
|
||||||
remove_metadata(conn, m[0])
|
remove_metadata(conn, m[0])
|
||||||
|
|
||||||
if check_diary:
|
# Close the connection before starting the multithreading part of the script
|
||||||
dt = datetime.fromtimestamp(m[1], tz=timezone(timedelta(hours=TZ)))
|
conn.close()
|
||||||
|
|
||||||
|
if check_diary:
|
||||||
|
|
||||||
|
def check_jrnl(metadata: list):
|
||||||
|
dt = datetime.fromtimestamp(metadata[1], tz=timezone(timedelta(hours=TZ)))
|
||||||
diary_datetime = dt.strftime("%Y/%m/%d at %I:%M:%S %p")
|
diary_datetime = dt.strftime("%Y/%m/%d at %I:%M:%S %p")
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
|
@ -399,21 +413,38 @@ def doctor():
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
if not result.stdout:
|
return diary_datetime, result
|
||||||
print(
|
|
||||||
f"There is some metadata that is not associated with a diary entity: {diary_datetime}."
|
|
||||||
)
|
|
||||||
if not fix_diary:
|
|
||||||
print(
|
|
||||||
"You can automatically remove it by running the scripts with 'check_and_fix_diary' argument."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
remove_metadata(conn, m[0])
|
|
||||||
print("The problem was fixed.")
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e)
|
print(e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def process_metadata(m):
|
||||||
|
conn = db_connection(diary_path)
|
||||||
|
diary_datetime, result = check_jrnl(metadata=m)
|
||||||
|
|
||||||
|
if not result.stdout.strip():
|
||||||
|
print(
|
||||||
|
f"There is some metadata that is not associated with a diary entity: {diary_datetime}."
|
||||||
|
)
|
||||||
|
if not fix_diary:
|
||||||
|
print(
|
||||||
|
"You can automatically remove it by running the scripts with 'check_and_fix_diary' argument."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
remove_metadata(conn, m[0])
|
||||||
|
print("The problem was fixed.")
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||||
|
futures = {executor.submit(process_metadata, m): m for m in metadata}
|
||||||
|
|
||||||
|
for future in as_completed(futures):
|
||||||
|
try:
|
||||||
|
future.result()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Thread error: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def make_hash(file: Path):
|
def make_hash(file: Path):
|
||||||
sha256_hash = hashlib.sha256()
|
sha256_hash = hashlib.sha256()
|
||||||
|
@ -634,7 +665,10 @@ if __name__ == "__main__":
|
||||||
elif sys.argv[1] == "insert":
|
elif sys.argv[1] == "insert":
|
||||||
insert()
|
insert()
|
||||||
elif sys.argv[1] == "doctor":
|
elif sys.argv[1] == "doctor":
|
||||||
doctor()
|
cProfile.run("doctor()", "output.prof")
|
||||||
|
stats = pstats.Stats("output.prof")
|
||||||
|
stats.strip_dirs().sort_stats("cumulative").print_stats(10)
|
||||||
|
# doctor()
|
||||||
else:
|
else:
|
||||||
print("Unknown command")
|
print("Unknown command")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -30,9 +30,6 @@ mullvad-vpn &
|
||||||
# caffeine
|
# caffeine
|
||||||
caffeine start &
|
caffeine start &
|
||||||
|
|
||||||
# mega cloud
|
|
||||||
megasync &
|
|
||||||
|
|
||||||
# compositor
|
# compositor
|
||||||
picom --config ~/.picom.conf &
|
picom --config ~/.picom.conf &
|
||||||
|
|
||||||
|
@ -76,7 +73,12 @@ workrave &
|
||||||
|
|
||||||
# watchdog
|
# watchdog
|
||||||
watchmedo shell-command --pattern='*.org;*.txt;*.md;*.gpg;*.org_archive;*.sh' --recursive --ignore-directories -W --command "~/org/sync.sh" ~/org/ &
|
watchmedo shell-command --pattern='*.org;*.txt;*.md;*.gpg;*.org_archive;*.sh' --recursive --ignore-directories -W --command "~/org/sync.sh" ~/org/ &
|
||||||
watchmedo shell-command --pattern='*.journal;*.sh;*.log;*.prices;*.csv' --recursive --ignore-directories -W --command "~/.hledger/sync.sh" ~/.hledger/ &
|
watchmedo shell-command --pattern='*.journal;*.sh;*.log;*.prices;*.csv;*.py' --recursive --ignore-directories -W --command "~/.hledger/sync.sh" ~/.hledger/ &
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# mega cloud
|
||||||
|
megasync &
|
||||||
|
|
||||||
# lockscreen
|
# lockscreen
|
||||||
# xss-lock --transfer-sleep-lock -- ~/scripts/bin/lock.sh
|
# xss-lock --transfer-sleep-lock -- ~/scripts/bin/lock.sh
|
||||||
|
|
Loading…
Add table
Reference in a new issue