Skip to content

Commit 3c071f3

Browse files
committed
Add initialize_vfb_connect function to trigger lazy loading of VFB_connect properties
1 parent f4b8cad commit 3c071f3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ def get_dict_cursor():
5959
# Replace VfbConnect with SolrTermInfoFetcher
6060
vc = SolrTermInfoFetcher()
6161

62+
def initialize_vfb_connect():
63+
"""
64+
Initialize VFB_connect by triggering the lazy load of the vfb and nc properties.
65+
This causes VFB_connect to cache all terms, which takes ~95 seconds on first call.
66+
Subsequent calls to functions using vc.nc will be fast.
67+
68+
:return: True if initialization successful, False otherwise
69+
"""
70+
try:
71+
# Access the properties to trigger lazy loading
72+
_ = vc.vfb
73+
_ = vc.nc
74+
return True
75+
except Exception as e:
76+
print(f"Failed to initialize VFB_connect: {e}")
77+
return False
78+
6279
class Query:
6380
def __init__(self, query, label, function, takes, preview=0, preview_columns=[], preview_results=[], output_format="table", count=-1):
6481
self.query = query

0 commit comments

Comments
 (0)