![Finn Stutzenstein](/assets/img/avatar_default.png)
- Cleans up log messages in the client - Refactored the autoupdate bundle code into an own file - Added bulk creates for History in Postgresql. This is the only database system that supports returning all ids whan multiple elements are inserted. We can make usage out of it. - Added a `disable_history`, that is request-wide - Disabled history on poll vote requests - Removed unnecessary user ordering - Reduced the queries for creating motion vote objects by one - removed final_data: This was not prefetched. Using the normal data collection the data is prefetched - removed unnecessary user query if vore delegation is not used
22 lines
742 B
Python
22 lines
742 B
Python
from django.db import connection
|
|
|
|
|
|
def is_postgres() -> bool:
|
|
return connection.vendor == "postgresql"
|
|
|
|
|
|
def restart_id_sequence(table_name: str) -> None:
|
|
"""
|
|
This function resets the id sequence from the given table (the current auto
|
|
increment value for the id field) to the max_id+1. This is needed, when manually
|
|
inserting object id, because Postgresql does not update the id sequence in this case.
|
|
"""
|
|
if not is_postgres():
|
|
return
|
|
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(f"SELECT max(id) + 1 as max FROM {table_name};")
|
|
max_id = cursor.fetchone()[0]
|
|
if max_id is not None:
|
|
cursor.execute(f"ALTER SEQUENCE {table_name}_id_seq RESTART WITH {max_id};")
|