forked from CGM_Public/pretix_original
Offload more work to database replica
This commit is contained in:
@@ -76,3 +76,21 @@ class GroupConcat(Aggregate):
|
||||
function='string_agg',
|
||||
template="%(function)s(%(field)s::text, '%(separator)s')",
|
||||
)
|
||||
|
||||
|
||||
class ReplicaRouter:
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
return 'default'
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
return 'default'
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
db_list = ('default', 'replica')
|
||||
if obj1._state.db in db_list and obj2._state.db in db_list:
|
||||
return True
|
||||
return None
|
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hintrs):
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user