|
1 | 1 | import time
|
2 | 2 | start = time.time()
|
3 | 3 | import streamlit as st
|
| 4 | +st.write("Streamlit import", time.time() - start) |
| 5 | +start = time.time() |
4 | 6 | from settings import initialize
|
| 7 | +st.write("Settings import", time.time() - start) |
| 8 | +start = time.time() |
5 | 9 | from ui_components import create_funnels
|
| 10 | +st.write("UI Components", time.time() - start) |
| 11 | +start = time.time() |
6 | 12 | import ui_widgets as ui
|
7 |
| -import users |
8 |
| -from metrics import get_user_cohort_list |
| 13 | +st.write("UI Widgets", time.time() - start) |
9 | 14 |
|
10 |
| -st.write("Imports done", time.time() - start) |
11 | 15 | initialize()
|
12 | 16 |
|
13 | 17 | ui.display_definitions_table("Data Notes",ui.data_notes)
|
14 |
| -countries_list = users.get_country_list() |
| 18 | + |
| 19 | +@st.cache_data |
| 20 | +def load_countries(): |
| 21 | + from users import get_country_list |
| 22 | + return get_country_list() |
| 23 | + |
| 24 | +countries_list = load_countries() |
15 | 25 |
|
16 | 26 | ui.colorize_multiselect_options()
|
17 | 27 |
|
|
24 | 34 | daterange = ui.convert_date_to_range(selected_date, option)
|
25 | 35 |
|
26 | 36 | with col_lang:
|
27 |
| - languages = users.get_language_list() |
| 37 | + @st.cache_data |
| 38 | + def load_languages(): |
| 39 | + from users import get_language_list |
| 40 | + return get_language_list() |
| 41 | + |
| 42 | + languages = load_languages() |
| 43 | + |
28 | 44 | language = ui.single_selector(
|
29 | 45 | languages, placement="middle", title="Select a language", key="acq-1"
|
30 | 46 | )
|
|
53 | 69 |
|
54 | 70 | if len(daterange) == 2 and countries_list:
|
55 | 71 |
|
| 72 | + #delayed loading of import |
| 73 | + @st.cache_data(show_spinner="Loading user cohorts…") |
| 74 | + def get_user_cohort_list_lazy(daterange, languages, countries_list, app): |
| 75 | + from metrics import get_user_cohort_list |
| 76 | + return get_user_cohort_list( |
| 77 | + daterange=daterange, |
| 78 | + languages=languages, |
| 79 | + countries_list=countries_list, |
| 80 | + app=app |
| 81 | + ) |
| 82 | + |
56 | 83 | # --- Get user cohorts ---
|
57 |
| - user_cohort_list_unity = get_user_cohort_list( |
| 84 | + user_cohort_list_unity = get_user_cohort_list_lazy( |
58 | 85 | daterange=daterange,
|
59 | 86 | languages=language,
|
60 | 87 | countries_list=countries_list,
|
61 | 88 | app="Unity"
|
62 | 89 | )
|
63 |
| - user_cohort_list_cr = get_user_cohort_list( |
| 90 | + user_cohort_list_cr = get_user_cohort_list_lazy( |
64 | 91 | daterange=daterange,
|
65 | 92 | languages=language,
|
66 | 93 | countries_list=countries_list,
|
|
0 commit comments