File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 66isort:skip_file
77"""
88
9+ # FAL-2248: Monkey patch django's get_storage_engine to work around long migrations times.
10+ # This fixes a performance issue with database migrations in Ocim. We will need to keep
11+ # this patch in our opencraft-release/* branches until edx-platform upgrades to Django 4.*
12+ # which will include this commit:
13+ # https://github.com/django/django/commit/518ce7a51f994fc0585d31c4553e2072bf816f76
14+ import django .db .backends .mysql .introspection
915
1016# We monkey patch Kombu's entrypoints listing because scanning through this
1117# accounts for the majority of LMS/Studio startup time for tests, and we don't
2228# that shared_task will use this app, and also ensures that the celery
2329# singleton is always configured for the CMS.
2430from .celery import APP as CELERY_APP # lint-amnesty, pylint: disable=wrong-import-position
31+
32+
33+ def get_storage_engine (self , cursor , table_name ):
34+ """
35+ This is a patched version of `get_storage_engine` that fixes a
36+ performance issue with migrations. For more info see FAL-2248 and
37+ https://github.com/django/django/pull/14766
38+ """
39+ cursor .execute ("""
40+ SELECT engine
41+ FROM information_schema.tables
42+ WHERE table_name = %s
43+ AND table_schema = DATABASE()""" , [table_name ])
44+ result = cursor .fetchone ()
45+ if not result :
46+ return self .connection .features ._mysql_storage_engine # pylint: disable=protected-access
47+ return result [0 ]
48+
49+
50+ django .db .backends .mysql .introspection .DatabaseIntrospection .get_storage_engine = get_storage_engine
Original file line number Diff line number Diff line change 1818# that shared_task will use this app, and also ensures that the celery
1919# singleton is always configured for the LMS.
2020from .celery import APP as CELERY_APP # lint-amnesty, pylint: disable=wrong-import-position
21+
22+ # FAL-2248: Monkey patch django's get_storage_engine to work around long migrations times.
23+ # This fixes a performance issue with database migrations in Ocim. We will need to keep
24+ # this patch in our opencraft-release/* branches until edx-platform upgrades to Django 4.*
25+ # which will include this commit:
26+ # https://github.com/django/django/commit/518ce7a51f994fc0585d31c4553e2072bf816f76
27+ import django .db .backends .mysql .introspection
28+
29+
30+ def get_storage_engine (self , cursor , table_name ):
31+ """
32+ This is a patched version of `get_storage_engine` that fixes a
33+ performance issue with migrations. For more info see FAL-2248 and
34+ https://github.com/django/django/pull/14766
35+ """
36+ cursor .execute ("""
37+ SELECT engine
38+ FROM information_schema.tables
39+ WHERE table_name = %s
40+ AND table_schema = DATABASE()""" , [table_name ])
41+ result = cursor .fetchone ()
42+ if not result :
43+ return self .connection .features ._mysql_storage_engine # pylint: disable=protected-access
44+ return result [0 ]
45+
46+
47+ django .db .backends .mysql .introspection .DatabaseIntrospection .get_storage_engine = get_storage_engine
You can’t perform that action at this time.
0 commit comments