mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00

* Automatically elide empty inputs and outputs to backend methods * Refactor service generation Despite the fact that the majority of our Protobuf service methods require an open collection, they were not accessible with just a Collection object. To access the methods (e.g. because we haven't gotten around to exposing the correct API in Collection yet), you had to wrap the collection in a Backend object, and pay a mutex-acquisition cost for each call, even if you have exclusive access to the object. This commit migrates the majority of service methods to the Collection, so they can now be used directly, and improves the ergonomics a bit at the same time. The approach taken: - The service generation now happens in rslib instead of anki_proto, which avoids the need for trait constraints and associated types. - Service methods are assumed to be collection-based by default. Instead of implementing the service on Backend, we now implement it on Collection, which means our methods no longer need to use self.with_col(...). - We automatically generate methods in Backend which use self.with_col() to delegate to the Collection method. - For methods that are only appropriate for the backend, we add a flag in the .proto file. The codegen uses this flag to write the method into a BackendFooService instead of FooService, which the backend implements. - The flag can also allows us to define separate implementations for collection and backend, so we can e.g. skip the collection mutex in the i18n service while also providing the service on a collection.
142 lines
3.5 KiB
Protocol Buffer
142 lines
3.5 KiB
Protocol Buffer
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
syntax = "proto3";
|
|
|
|
option java_multiple_files = true;
|
|
|
|
package anki.collection;
|
|
|
|
import "anki/generic.proto";
|
|
import "anki/codegen.proto";
|
|
|
|
service CollectionService {
|
|
rpc OpenCollection(OpenCollectionRequest) returns (generic.Empty) {
|
|
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
|
|
}
|
|
rpc CloseCollection(CloseCollectionRequest) returns (generic.Empty) {
|
|
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
|
|
}
|
|
rpc CheckDatabase(generic.Empty) returns (CheckDatabaseResponse);
|
|
rpc GetUndoStatus(generic.Empty) returns (UndoStatus);
|
|
rpc Undo(generic.Empty) returns (OpChangesAfterUndo);
|
|
rpc Redo(generic.Empty) returns (OpChangesAfterUndo);
|
|
rpc AddCustomUndoEntry(generic.String) returns (generic.UInt32);
|
|
rpc MergeUndoEntries(generic.UInt32) returns (OpChanges);
|
|
rpc LatestProgress(generic.Empty) returns (Progress);
|
|
rpc SetWantsAbort(generic.Empty) returns (generic.Empty);
|
|
// Create a no-media backup. Caller must ensure there is no active
|
|
// transaction. Unlike a collection export, does not require reopening the DB,
|
|
// as there is no downgrade step.
|
|
// Returns false if it's not time to make a backup yet.
|
|
rpc CreateBackup(CreateBackupRequest) returns (generic.Bool) {
|
|
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
|
|
}
|
|
// If a backup is running, wait for it to complete. Will return an error
|
|
// if the backup encountered an error.
|
|
rpc AwaitBackupCompletion(generic.Empty) returns (generic.Empty) {
|
|
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
|
|
}
|
|
}
|
|
|
|
message OpenCollectionRequest {
|
|
string collection_path = 1;
|
|
string media_folder_path = 2;
|
|
string media_db_path = 3;
|
|
|
|
// temporary option for AnkiDroid
|
|
bool force_schema11 = 99;
|
|
}
|
|
|
|
message CloseCollectionRequest {
|
|
bool downgrade_to_schema11 = 1;
|
|
}
|
|
|
|
message CheckDatabaseResponse {
|
|
repeated string problems = 1;
|
|
}
|
|
|
|
message OpChanges {
|
|
bool card = 1;
|
|
bool note = 2;
|
|
bool deck = 3;
|
|
bool tag = 4;
|
|
bool notetype = 5;
|
|
bool config = 6;
|
|
bool deck_config = 11;
|
|
bool mtime = 12;
|
|
|
|
bool browser_table = 7;
|
|
bool browser_sidebar = 8;
|
|
// editor and displayed card in review screen
|
|
bool note_text = 9;
|
|
// whether to call .reset() and getCard()
|
|
bool study_queues = 10;
|
|
}
|
|
|
|
message OpChangesWithCount {
|
|
uint32 count = 1;
|
|
OpChanges changes = 2;
|
|
}
|
|
|
|
message OpChangesWithId {
|
|
int64 id = 1;
|
|
OpChanges changes = 2;
|
|
}
|
|
|
|
message UndoStatus {
|
|
string undo = 1;
|
|
string redo = 2;
|
|
uint32 last_step = 3;
|
|
}
|
|
|
|
message OpChangesAfterUndo {
|
|
OpChanges changes = 1;
|
|
string operation = 2;
|
|
int64 reverted_to_timestamp = 3;
|
|
UndoStatus new_status = 4;
|
|
uint32 counter = 5;
|
|
}
|
|
|
|
message Progress {
|
|
message MediaSync {
|
|
string checked = 1;
|
|
string added = 2;
|
|
string removed = 3;
|
|
}
|
|
|
|
message FullSync {
|
|
uint32 transferred = 1;
|
|
uint32 total = 2;
|
|
}
|
|
|
|
message NormalSync {
|
|
string stage = 1;
|
|
string added = 2;
|
|
string removed = 3;
|
|
}
|
|
|
|
message DatabaseCheck {
|
|
string stage = 1;
|
|
uint32 stage_total = 2;
|
|
uint32 stage_current = 3;
|
|
}
|
|
|
|
oneof value {
|
|
generic.Empty none = 1;
|
|
MediaSync media_sync = 2;
|
|
string media_check = 3;
|
|
FullSync full_sync = 4;
|
|
NormalSync normal_sync = 5;
|
|
DatabaseCheck database_check = 6;
|
|
string importing = 7;
|
|
string exporting = 8;
|
|
}
|
|
}
|
|
|
|
message CreateBackupRequest {
|
|
string backup_folder = 1;
|
|
// Create a backup even if the configured interval hasn't elapsed yet.
|
|
bool force = 2;
|
|
bool wait_for_completion = 3;
|
|
}
|