    def _init_share_query(self, kind="share"):
        """Initialize a query for Shares

        before applying filters

        A method so we can consolidate joins, etc.
        """
        if kind == "share":
            class_ = orm.Share
        elif kind == "code":
            class_ = orm.ShareCode
        else:
            raise ValueError(
                f"kind must be `share` or `code`, not {kind!r}"
            )  # pragma: no cover

        query = self.db.query(class_).options(
            joinedload(class_.owner).lazyload("*"),
            joinedload(class_.spawner).joinedload(orm.Spawner.user).lazyload("*"),
        )
        if kind == 'share':
            query = query.options(
                joinedload(class_.user).joinedload(orm.User.groups).lazyload("*"),
                joinedload(class_.group).lazyload("*"),
            )
        return query
Initialize a query for Shares

before applying filters

A method so we can consolidate joins, etc.
jupyterhub/apihandlers/shares.py