def METHOD_NAME(user_id: int | None) -> dict[str, Any]:
    # send list of tab state ids
    tabs_state = (
        db.session.query(TabState.id, TabState.label).filter_by(user_id=user_id).all()
    )
    tab_state_ids = [str(tab_state[0]) for tab_state in tabs_state]
    # return first active tab, or fallback to another one if no tab is active
    active_tab = (
        db.session.query(TabState)
        .filter_by(user_id=user_id)
        .order_by(TabState.active.desc())
        .first()
    )
    databases: dict[int, Any] = {}
    for database in DatabaseDAO.find_all():
        databases[database.id] = {
            k: v for k, v in database.to_json().items() if k in DATABASE_KEYS
        }
        databases[database.id]["backend"] = database.backend
    queries: dict[str, Any] = {}
    # These are unnecessary if sqllab backend persistence is disabled
    if is_feature_enabled("SQLLAB_BACKEND_PERSISTENCE"):
        # return all user queries associated with existing SQL editors
        user_queries = (
            db.session.query(Query)
            .filter_by(user_id=user_id)
            .filter(Query.sql_editor_id.in_(tab_state_ids))
            .all()
        )
        queries = {
            query.client_id: dict(query.to_dict().items()) for query in user_queries
        }
    return {
        "tab_state_ids": tabs_state,
        "active_tab": active_tab.to_dict() if active_tab else None,
        "databases": databases,
        "queries": queries,
    }