This commit is contained in:
retoor 2025-07-04 09:29:03 +02:00
parent 634aa535de
commit 5c6d837f10
2 changed files with 14 additions and 16 deletions

View File

@ -10,10 +10,11 @@ class BaseMapper:
model_class: BaseModel = None model_class: BaseModel = None
default_limit: int = DEFAULT_LIMIT default_limit: int = DEFAULT_LIMIT
table_name: str = None table_name: str = None
semaphore = asyncio.Semaphore(1)
def __init__(self, app): def __init__(self, app):
self.app = app self.app = app
self.semaphore = asyncio.Semaphore(1)
self.default_limit = self.__class__.default_limit self.default_limit = self.__class__.default_limit
@property @property
@ -26,19 +27,16 @@ class BaseMapper:
async def run_in_executor(self, func, *args, **kwargs): async def run_in_executor(self, func, *args, **kwargs):
use_semaphore = kwargs.pop("use_semaphore", False) use_semaphore = kwargs.pop("use_semaphore", False)
if use_semaphore:
async with self.semaphore: def _execute():
database_exception = None result = func(*args, **kwargs)
for x in range(20): if use_semaphore:
try: self.db.commit()
result = func(*args, **kwargs) return result
self.db.commit()
return result async with self.semaphore:
except Exception as ex: return await self.loop.run_in_executor(None, _execute)
await asyncio.sleep(0)
database_exception = ex
raise database_exception
return await self.loop.run_in_executor(None, lambda: func(*args, **kwargs))
async def new(self): async def new(self):
return self.model_class(mapper=self, app=self.app) return self.model_class(mapper=self, app=self.app)

View File

@ -32,7 +32,7 @@
{% endfor %} {% endfor %}
<div class="message-list-bottom"></div> <div class="message-list-bottom"></div>
</message-list> </message-list>
<chat-input live-type="false" channel="{{ channel.uid.value }}"></chat-input> <chat-input live-type="true" channel="{{ channel.uid.value }}"></chat-input>
</section> </section>
{% include "dialog_container.html" %} {% include "dialog_container.html" %}
{% include "dialog_help.html" %} {% include "dialog_help.html" %}