File size: 824 Bytes
989fb8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)