OpenSlides / OpenSlides/openslides-backend

[ReaAct] Lock via automatic JOIN queries

Open
#3,763 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9
Forks
40
Avg merge
1d 22h
Merged PRs (30d)
19

Description

  • Specifying a dictionary of requested models and some of its fields and relations should automatically create a JOIN query.
  • This should also specify if the models should be locked for update, having the advantage that models/rows are locked at once.
  • filter data structure or client autoupdate subscription data structure might be an inspiration on how to do it

Example from BaseMigration:

join_on_parts: list[sql.Composable] = []
for table, join_on_columns in additional_source_tables.items():
    join_on_parts.append(
        get_join_table_part(table, join_on_columns)
    )
    join_on = sql.SQL(" ").join(join_on_parts)

def get_join_table_part(
right_table: Table, join_on_columns: dict[Field, tuple[Table, Field]]
) -> sql.Composable:
    return sql.SQL(" JOIN {right_table} ON {columns}").format(
        right_table=sql.Identifier(right_table),
        columns=sql.SQL(" AND ").join(
        sql.SQL(
           "{right_table}.{right_column} = {left_table}.{left_column}"
        ).format(
            right_table=sql.Identifier(right_table),
            right_column=sql.Identifier(right_column),
            left_table=sql.Identifier(left_table_and_column[0]),
            left_column=sql.Identifier(left_table_and_column[1]),
        )
        for right_column, left_table_and_column in join_on_columns.items()
    ),
)

Example of additional_source_tables:

main_source_table = "vote_t"
additional_source_tables={
    "meeting_user_t": {
        "user_id": ("vote_t", "user_id"),
        "meeting_id": ("vote_t", "meeting_id"),
    },
    "option_t": {"id": ("vote_t", "option_id")},
    "poll_t": {"id": ("option_t", "poll_id")}
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the BaseMigration JOIN example and compare it with the filter data structure and client autoupdate subscription data structure mentioned in the issue. Define how requested models, fields, relations, and update locking should be represented, then verify that the resulting query joins the required tables and locks the requested rows together.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.