Skip to content

editoast: model: use streams instead of collecting #13989

@leovalais

Description

@leovalais

Description and goal

In all batching functions, we require a collection to collect into. This is unnecessary because diesel supports row streaming. We can only generate the streaming model functions and implement all others by default.

=> In all -Unchecked model batch traits, add a -_stream function that returns a TryStream, as provided by diesel's .load_stream. Then only generate this function in derive(Model). All others can be implemented by default using that.

Do not change the signatures of the current functions to avoid a massive refactoring (it'll come at some point since streams are superior, but one thing at a time).

The List trait can also benefit from a stream function.

Example for retrieve:

    fn retrieve_stream(
        conn: DbConnection,
        ids: impl IntoIterator<Item = K> + Send,
    ) -> impl futures::TryStream<Ok = Self, Error = Self::Error>;

This work should reduce the amount of generated code and reduce unnecessary allocations eventually.

Acceptance criteria

yes

Metadata

Metadata

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions