remove unused set_all_config; expose .all_config().

This commit is contained in:
Damien Elmes 2021-01-29 16:30:42 +10:00
parent 4ac9ad1407
commit 7693879e3c
3 changed files with 18 additions and 15 deletions

View file

@ -25,7 +25,15 @@ from anki.errors import AnkiError
from anki.media import MediaManager, media_paths_from_col_path from anki.media import MediaManager, media_paths_from_col_path
from anki.models import ModelManager from anki.models import ModelManager
from anki.notes import Note from anki.notes import Note
from anki.rsbackend import TR, DBError, FormatTimeSpanContext, Progress, RustBackend, pb from anki.rsbackend import (
TR,
DBError,
FormatTimeSpanContext,
Progress,
RustBackend,
from_json_bytes,
pb,
)
from anki.sched import Scheduler as V1Scheduler from anki.sched import Scheduler as V1Scheduler
from anki.schedv2 import Scheduler as V2Scheduler from anki.schedv2 import Scheduler as V2Scheduler
from anki.tags import TagManager from anki.tags import TagManager
@ -484,6 +492,10 @@ class Collection:
self.setMod() self.setMod()
self.conf.remove(key) self.conf.remove(key)
def all_config(self) -> Dict[str, Any]:
"This is a debugging aid. Prefer .get_config() when you know the key you need."
return from_json_bytes(self.backend.get_all_config())
# Stats # Stats
########################################################################## ##########################################################################

View file

@ -214,13 +214,15 @@ service BackendService {
rpc ClearTag(String) returns (Empty); rpc ClearTag(String) returns (Empty);
rpc TagTree(Empty) returns (TagTreeNode); rpc TagTree(Empty) returns (TagTreeNode);
// config/preferences // config
rpc GetConfigJson(String) returns (Json); rpc GetConfigJson(String) returns (Json);
rpc SetConfigJson(SetConfigJsonIn) returns (Empty); rpc SetConfigJson(SetConfigJsonIn) returns (Empty);
rpc RemoveConfig(String) returns (Empty); rpc RemoveConfig(String) returns (Empty);
rpc SetAllConfig(Json) returns (Empty);
rpc GetAllConfig(Empty) returns (Json); rpc GetAllConfig(Empty) returns (Json);
// preferences
rpc GetPreferences(Empty) returns (Preferences); rpc GetPreferences(Empty) returns (Preferences);
rpc SetPreferences(Preferences) returns (Empty); rpc SetPreferences(Preferences) returns (Empty);
} }

View file

@ -57,7 +57,7 @@ use pb::{sync_status_out, BackendService};
use prost::Message; use prost::Message;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use slog::warn; use slog::warn;
use std::collections::{HashMap, HashSet}; use std::collections::HashSet;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::{ use std::{
result, result,
@ -1413,17 +1413,6 @@ impl BackendService for Backend {
.map(Into::into) .map(Into::into)
} }
fn set_all_config(&self, input: pb::Json) -> BackendResult<Empty> {
let val: HashMap<String, JsonValue> = serde_json::from_slice(&input.json)?;
self.with_col(|col| {
col.transact(None, |col| {
col.storage
.set_all_config(val, col.usn()?, TimestampSecs::now())
})
})
.map(Into::into)
}
fn get_all_config(&self, _input: Empty) -> BackendResult<pb::Json> { fn get_all_config(&self, _input: Empty) -> BackendResult<pb::Json> {
self.with_col(|col| { self.with_col(|col| {
let conf = col.storage.get_all_config()?; let conf = col.storage.get_all_config()?;