From 719851cd92d7215a4767d385bdba5db0708535ee Mon Sep 17 00:00:00 2001 From: perast Date: Thu, 12 Nov 2020 08:45:10 +0100 Subject: [PATCH 01/10] Hopefully fix db connections (locked) --- zwift_offline.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zwift_offline.py b/zwift_offline.py index ecd8bb9..732d646 100644 --- a/zwift_offline.py +++ b/zwift_offline.py @@ -1242,6 +1242,8 @@ def relay_worlds_leave(world_id): @app.teardown_request def teardown_request(exception): + db.close_all_sessions() + db.session.close() if exception != None: print('Exception: %s' % exception) @@ -1284,7 +1286,6 @@ def init_database(): def check_columns(): - time.sleep(3) rows = db.engine.execute(sqlalchemy.text("PRAGMA table_info(user)")) should_have_columns = User.metadata.tables['user'].columns current_columns = list() @@ -1315,8 +1316,7 @@ def before_first_request(): init_database() db.create_all(app=app) db.session.commit() - check_columns_thread = threading.Thread(target=check_columns) - check_columns_thread.start() + check_columns() send_message_thread = threading.Thread(target=send_server_back_online_message) send_message_thread.start() @@ -1460,6 +1460,7 @@ def run_standalone(passedOnline, passedGhostsEnabled, passedSaveGhost, passedPla if not MULTIPLAYER: login_manager.anonymous_user = AnonUser login_manager.init_app(app) + db.close_all_sessions() @login_manager.user_loader def load_user(uid): From 526d956a27db70dc73ed9d68e86ddc3549814bee Mon Sep 17 00:00:00 2001 From: perast Date: Thu, 12 Nov 2020 09:56:50 +0100 Subject: [PATCH 02/10] Added excluded files to proxy Fix for goal week period --- standalone.py | 3 ++- zwift_offline.py | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/standalone.py b/standalone.py index 33f6ee5..eec8aa9 100755 --- a/standalone.py +++ b/standalone.py @@ -188,7 +188,8 @@ class CDNHandler(SimpleHTTPRequestHandler): return exceptions = ['Launcher_ver_cur.xml', 'LauncherMac_ver_cur.xml', 'Zwift_ver_cur.xml', 'ZwiftMac_ver_cur.xml', - 'ZwiftAndroid_ver_cur.xml', 'Zwift_StreamingFiles_ver_cur.xml'] + 'ZwiftAndroid_ver_cur.xml', 'Zwift_StreamingFiles_ver_cur.xml', + 'site.css', 'MapSchedule_v2.xml', 'background.jpg'] if os.path.exists(PROXYPASS_FILE) and self.path.startswith('/gameassets/') and not path_end in exceptions: # PROXYPASS_FILE existence indicates we know what we're doing and # we can try to obtain the official map schedule and update files. diff --git a/zwift_offline.py b/zwift_offline.py index 732d646..6c573aa 100644 --- a/zwift_offline.py +++ b/zwift_offline.py @@ -852,14 +852,9 @@ def api_profiles_followees(player_id): def get_week_range(dt): - d = datetime.datetime(dt.year,1,1) - if (d.weekday()<= 3): - d = d - timedelta(d.weekday()) - else: - d = d + timedelta(7-d.weekday()) - dlt = timedelta(days = (int(dt.strftime('%W'))-1)*7) - first = d + dlt - last = d + dlt + timedelta(days=6, hours=23, minutes=59, seconds=59) + d = datetime.datetime(dt.year,dt.month,dt.day - dt.weekday()) + first = d + last = d + timedelta(days=6, hours=23, minutes=59, seconds=59) return first, last def get_month_range(dt): From bbb38a6b5b7949a4a5155b67b460ffa8528f1d3e Mon Sep 17 00:00:00 2001 From: perast Date: Thu, 12 Nov 2020 10:26:06 +0100 Subject: [PATCH 03/10] Added logging of SQL warnings Added db.engine.dispose() --- zwift_offline.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zwift_offline.py b/zwift_offline.py index 6c573aa..f187842 100644 --- a/zwift_offline.py +++ b/zwift_offline.py @@ -42,6 +42,7 @@ import protobuf.hash_seeds_pb2 as hash_seeds_pb2 logging.basicConfig(filename='zoffline.log', level=os.environ.get("LOGLEVEL", "INFO")) logger = logging.getLogger('zoffline') logger.setLevel(logging.WARN) +logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN) if os.name == 'nt' and platform.release() == '10' and platform.version() >= '10.0.14393': # Fix ANSI color in Windows 10 version 10.0.14393 (Windows Anniversary Update) @@ -1239,6 +1240,7 @@ def relay_worlds_leave(world_id): def teardown_request(exception): db.close_all_sessions() db.session.close() + db.engine.dispose() if exception != None: print('Exception: %s' % exception) @@ -1456,6 +1458,7 @@ def run_standalone(passedOnline, passedGhostsEnabled, passedSaveGhost, passedPla login_manager.anonymous_user = AnonUser login_manager.init_app(app) db.close_all_sessions() + db.engine.dispose() @login_manager.user_loader def load_user(uid): From 75f4394563a51e33f0747ff902172f7f9803ef48 Mon Sep 17 00:00:00 2001 From: perast Date: Thu, 12 Nov 2020 11:27:15 +0100 Subject: [PATCH 04/10] Moved style files, removed exceptions in proxy --- cdn/static/web/launcher/embed.html | 2 +- cdn/static/web/launcher/layout.html | 2 +- cdn/{gameassets => style}/background.jpg | Bin cdn/{gameassets => style}/site.css | 2 +- standalone.py | 3 +-- zwift_offline.py | 8 +++++++- 6 files changed, 11 insertions(+), 6 deletions(-) rename cdn/{gameassets => style}/background.jpg (100%) rename cdn/{gameassets => style}/site.css (91%) diff --git a/cdn/static/web/launcher/embed.html b/cdn/static/web/launcher/embed.html index 0a7f08d..e1916fb 100644 --- a/cdn/static/web/launcher/embed.html +++ b/cdn/static/web/launcher/embed.html @@ -2,7 +2,7 @@ Loading Zwift - +
diff --git a/cdn/static/web/launcher/layout.html b/cdn/static/web/launcher/layout.html index 5b4e3c5..c087606 100644 --- a/cdn/static/web/launcher/layout.html +++ b/cdn/static/web/launcher/layout.html @@ -3,7 +3,7 @@ Zwift Launcher - +