mirror of
https://github.com/ankitects/anki.git
synced 2026-01-07 02:53:54 -05:00
Perf: Prevent partial template being sent to frontend
This commit is contained in:
parent
87650f5767
commit
286daac650
3 changed files with 16 additions and 11 deletions
|
|
@ -307,6 +307,11 @@ message NextCardDataResponse {
|
||||||
bool stop_on_answer = 2;
|
bool stop_on_answer = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message PartialTemplate {
|
||||||
|
repeated card_rendering.RenderedTemplateNode front = 1;
|
||||||
|
repeated card_rendering.RenderedTemplateNode back = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message NextCardData {
|
message NextCardData {
|
||||||
QueuedCards queue = 1;
|
QueuedCards queue = 1;
|
||||||
repeated AnswerButton answer_buttons = 2;
|
repeated AnswerButton answer_buttons = 2;
|
||||||
|
|
@ -334,13 +339,7 @@ message NextCardDataResponse {
|
||||||
deck_config.DeckConfig.Config.QuestionAction autoAdvanceQuestionAction = 18;
|
deck_config.DeckConfig.Config.QuestionAction autoAdvanceQuestionAction = 18;
|
||||||
deck_config.DeckConfig.Config.AnswerAction autoAdvanceAnswerAction = 19;
|
deck_config.DeckConfig.Config.AnswerAction autoAdvanceAnswerAction = 19;
|
||||||
|
|
||||||
// TODO: We can probably make this a little faster by using oneof and
|
optional PartialTemplate partialTemplate = 11;
|
||||||
// preventing the partial_front and back being sent to svelte where it isn't
|
|
||||||
// used. Alternatively we can use a completely different message for both
|
|
||||||
// Rust -> Python and the Python -> Svelte though this would be more
|
|
||||||
// complicated to implement.
|
|
||||||
repeated card_rendering.RenderedTemplateNode partial_front = 10;
|
|
||||||
repeated card_rendering.RenderedTemplateNode partial_back = 11;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
optional NextCardData next_card = 1;
|
optional NextCardData next_card = 1;
|
||||||
|
|
|
||||||
|
|
@ -711,16 +711,19 @@ def next_card_data() -> bytes:
|
||||||
ctx = TemplateRenderContext.from_existing_card(card, False)
|
ctx = TemplateRenderContext.from_existing_card(card, False)
|
||||||
|
|
||||||
qside = apply_custom_filters(
|
qside = apply_custom_filters(
|
||||||
PartiallyRenderedCard.nodes_from_proto(data.next_card.partial_front),
|
PartiallyRenderedCard.nodes_from_proto(data.next_card.partialTemplate.front),
|
||||||
ctx,
|
ctx,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
aside = apply_custom_filters(
|
aside = apply_custom_filters(
|
||||||
PartiallyRenderedCard.nodes_from_proto(data.next_card.partial_back),
|
PartiallyRenderedCard.nodes_from_proto(data.next_card.partialTemplate.back),
|
||||||
ctx,
|
ctx,
|
||||||
qside,
|
qside,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Dont send the partialy rendered template to the frontend to save bandwidth
|
||||||
|
data.next_card.ClearField("partialTemplate")
|
||||||
|
|
||||||
q_avtags = ctx.col()._backend.extract_av_tags(text=qside, question_side=True)
|
q_avtags = ctx.col()._backend.extract_av_tags(text=qside, question_side=True)
|
||||||
a_avtags = ctx.col()._backend.extract_av_tags(text=aside, question_side=False)
|
a_avtags = ctx.col()._backend.extract_av_tags(text=aside, question_side=False)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use anki_proto::generic;
|
||||||
use anki_proto::scheduler;
|
use anki_proto::scheduler;
|
||||||
use anki_proto::scheduler::next_card_data_response::AnswerButton;
|
use anki_proto::scheduler::next_card_data_response::AnswerButton;
|
||||||
use anki_proto::scheduler::next_card_data_response::NextCardData;
|
use anki_proto::scheduler::next_card_data_response::NextCardData;
|
||||||
|
use anki_proto::scheduler::next_card_data_response::PartialTemplate;
|
||||||
use anki_proto::scheduler::next_card_data_response::TimerPreferences;
|
use anki_proto::scheduler::next_card_data_response::TimerPreferences;
|
||||||
use anki_proto::scheduler::next_card_data_response::TypedAnswer;
|
use anki_proto::scheduler::next_card_data_response::TypedAnswer;
|
||||||
use anki_proto::scheduler::ComputeFsrsParamsResponse;
|
use anki_proto::scheduler::ComputeFsrsParamsResponse;
|
||||||
|
|
@ -499,8 +500,10 @@ impl crate::services::SchedulerService for Collection {
|
||||||
queue: Some(queue.into()),
|
queue: Some(queue.into()),
|
||||||
|
|
||||||
css: render.css.clone(),
|
css: render.css.clone(),
|
||||||
partial_front: rendered_nodes_to_proto(q_nodes),
|
partial_template: Some(PartialTemplate {
|
||||||
partial_back: rendered_nodes_to_proto(render.anodes),
|
front: rendered_nodes_to_proto(q_nodes),
|
||||||
|
back: rendered_nodes_to_proto(render.anodes),
|
||||||
|
}),
|
||||||
|
|
||||||
answer_buttons,
|
answer_buttons,
|
||||||
autoplay: !deck_config.disable_autoplay,
|
autoplay: !deck_config.disable_autoplay,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue