danbooru2023-sqlite / profiling.py
KBlueLeaf's picture
Add FTS to tag_llist* field
989fb8b verified
from time import time_ns as tns
from db import *
print('warm up for tag_cache')
posts = list(Post.select().where(Post.tag_list.contains("$6KMR#")))
print('start profiling')
t0 = tns()
posts = list(
Post.select(Post, PostFTS)
.join(PostFTS, on = (Post.id == PostFTS.rowid))
.where(PostFTS.tag_list.match('"$6KMR#"'))
)
t1 = tns()
print((t1 - t0) / 1e9)
print(len(posts))
t0 = tns()
data = list(
i[0]
for i in db.execute_sql(
"SELECT id FROM post WHERE tag_list LIKE '%$6KMR#%';"
).fetchall()
)
posts = list(Post.select().where(Post.id << data))
t1 = tns()
print((t1 - t0) / 1e9)
print(len(data))
print(posts[0].tag_list)
t0 = tns()
posts = list(Post.select().where(Post.tag_list.contains("$6KMR#")))
t1 = tns()
print((t1 - t0) / 1e9)
print(len(posts))
print(posts[0].tag_list)