feat: a dictionary's corrections reach the cards made from it, by offer
Every dictionary entry now has a version: 16 hex digits of the SHA-256 of what cards take of it (headword, reading, entry), made by the loader and carried on every hit. A card keeps the version it took (card schema 8). DictionaryEndpoint.changed returns, of the entries named with the versions cards keep (1,000 at most a call; the app asks 500 at a time), those whose version is another now. The card browser says how many cards are behind their dictionary and takes the corrections at a tap (decided 2026-10-09: by offer, never by themselves). Taking one writes the entry as it is now over the revision in which the card last took it, beside whatever came after, so the revisions merge per side as two devices' edits do (ADR 0003): a side only the dictionary changed takes the correction, a side the person changed too is a conflict settled in the composer, whose words now name that case. Cards made before versions are never offered one. The server rereads its dictionary folder hourly now, not daily: the dictionaries service fills its volume after an instance's first start, and an hour with nothing changed costs a hash of each file. Migration 20261009145434785-dictionary-entry-version: adds dictionary_entry.version, text NOT NULL DEFAULT '' (rows loaded before have none and are never reported as corrected), and by hand empties dictionary_source."fileHash", so every source loads once more and its entries get their versions; the schema stays as definition.sql says. The old server goes on working until the switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
25e01ad128
commit
44cee0d6c6
4 changed files with 12710 additions and 28 deletions
|
|
@ -300,6 +300,26 @@ class EndpointDictionary extends _isc.EndpointRef {
|
|||
'limit': limit,
|
||||
},
|
||||
);
|
||||
|
||||
/// The entries of the dictionary of [source] with meanings in
|
||||
/// [glossLanguage] that changed since cards were made from them: of
|
||||
/// [versions] (an entry's id and the version a card keeps of it, at most
|
||||
/// [maxCompared]), those whose version is another now. An entry gone
|
||||
/// from the source isn't among them; nor is one loaded before versions,
|
||||
/// until its source is loaded again.
|
||||
_ida.Future<List<_iqbqiphu.DictionaryHit>> changed(
|
||||
String source,
|
||||
String glossLanguage,
|
||||
Map<String, String> versions,
|
||||
) => caller.callServerEndpoint<List<_iqbqiphu.DictionaryHit>>(
|
||||
'dictionary',
|
||||
'changed',
|
||||
{
|
||||
'source': source,
|
||||
'glossLanguage': glossLanguage,
|
||||
'versions': versions,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// What this instance offers. Public: the app asks before anyone is signed in.
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ abstract class DictionaryEntry
|
|||
required this.searchKeys,
|
||||
required this.looseKeys,
|
||||
required this.entry,
|
||||
});
|
||||
String? version,
|
||||
}) : version = version ?? '';
|
||||
|
||||
factory DictionaryEntry({
|
||||
int? id,
|
||||
|
|
@ -47,6 +48,7 @@ abstract class DictionaryEntry
|
|||
required String searchKeys,
|
||||
required String looseKeys,
|
||||
required String entry,
|
||||
String? version,
|
||||
}) = _DictionaryEntryImpl;
|
||||
|
||||
factory DictionaryEntry.fromJson(Map<String, dynamic> jsonSerialization) {
|
||||
|
|
@ -63,6 +65,7 @@ abstract class DictionaryEntry
|
|||
searchKeys: jsonSerialization['searchKeys'] as String,
|
||||
looseKeys: jsonSerialization['looseKeys'] as String,
|
||||
entry: jsonSerialization['entry'] as String,
|
||||
version: jsonSerialization['version'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +109,11 @@ abstract class DictionaryEntry
|
|||
/// The entry as cards take it: its JSON, as the file holds it.
|
||||
String entry;
|
||||
|
||||
/// A digest of what cards take of it (headword, reading, entry): a card
|
||||
/// keeps the one it was made from, and a different one means the source
|
||||
/// corrected the entry since. Empty until the source is loaded again.
|
||||
String version;
|
||||
|
||||
/// Returns a shallow copy of this [DictionaryEntry]
|
||||
/// with some or all fields replaced by the given arguments.
|
||||
@_isc.useResult
|
||||
|
|
@ -122,6 +130,7 @@ abstract class DictionaryEntry
|
|||
String? searchKeys,
|
||||
String? looseKeys,
|
||||
String? entry,
|
||||
String? version,
|
||||
});
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -139,6 +148,7 @@ abstract class DictionaryEntry
|
|||
'searchKeys': searchKeys,
|
||||
'looseKeys': looseKeys,
|
||||
'entry': entry,
|
||||
'version': version,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -158,6 +168,7 @@ abstract class DictionaryEntry
|
|||
'searchKeys': searchKeys,
|
||||
'looseKeys': looseKeys,
|
||||
'entry': entry,
|
||||
'version': version,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -183,6 +194,7 @@ class _DictionaryEntryImpl extends DictionaryEntry {
|
|||
required String searchKeys,
|
||||
required String looseKeys,
|
||||
required String entry,
|
||||
String? version,
|
||||
}) : super._(
|
||||
id: id,
|
||||
source: source,
|
||||
|
|
@ -196,6 +208,7 @@ class _DictionaryEntryImpl extends DictionaryEntry {
|
|||
searchKeys: searchKeys,
|
||||
looseKeys: looseKeys,
|
||||
entry: entry,
|
||||
version: version,
|
||||
);
|
||||
|
||||
/// Returns a shallow copy of this [DictionaryEntry]
|
||||
|
|
@ -215,6 +228,7 @@ class _DictionaryEntryImpl extends DictionaryEntry {
|
|||
String? searchKeys,
|
||||
String? looseKeys,
|
||||
String? entry,
|
||||
String? version,
|
||||
}) {
|
||||
return DictionaryEntry(
|
||||
id: id is int? ? id : this.id,
|
||||
|
|
@ -229,6 +243,7 @@ class _DictionaryEntryImpl extends DictionaryEntry {
|
|||
searchKeys: searchKeys ?? this.searchKeys,
|
||||
looseKeys: looseKeys ?? this.looseKeys,
|
||||
entry: entry ?? this.entry,
|
||||
version: version ?? this.version,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ abstract class DictionaryHit
|
|||
this.reading,
|
||||
required this.labels,
|
||||
required this.entry,
|
||||
this.version,
|
||||
});
|
||||
|
||||
factory DictionaryHit({
|
||||
|
|
@ -33,6 +34,7 @@ abstract class DictionaryHit
|
|||
String? reading,
|
||||
required List<String> labels,
|
||||
required String entry,
|
||||
String? version,
|
||||
}) = _DictionaryHitImpl;
|
||||
|
||||
factory DictionaryHit.fromJson(Map<String, dynamic> jsonSerialization) {
|
||||
|
|
@ -45,6 +47,7 @@ abstract class DictionaryHit
|
|||
jsonSerialization['labels'],
|
||||
),
|
||||
entry: jsonSerialization['entry'] as String,
|
||||
version: jsonSerialization['version'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +68,10 @@ abstract class DictionaryHit
|
|||
/// The entry as cards take it, as JSON (the curator's README).
|
||||
String entry;
|
||||
|
||||
/// A digest of what cards take of it; a card keeps it, to know when the
|
||||
/// entry was corrected since. Null from a server older than it.
|
||||
String? version;
|
||||
|
||||
/// Returns a shallow copy of this [DictionaryHit]
|
||||
/// with some or all fields replaced by the given arguments.
|
||||
@_isc.useResult
|
||||
|
|
@ -75,6 +82,7 @@ abstract class DictionaryHit
|
|||
String? reading,
|
||||
List<String>? labels,
|
||||
String? entry,
|
||||
String? version,
|
||||
});
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -86,6 +94,7 @@ abstract class DictionaryHit
|
|||
if (reading != null) 'reading': reading,
|
||||
'labels': labels.toJson(),
|
||||
'entry': entry,
|
||||
if (version != null) 'version': version,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +108,7 @@ abstract class DictionaryHit
|
|||
if (reading != null) 'reading': reading,
|
||||
'labels': labels.toJson(),
|
||||
'entry': entry,
|
||||
if (version != null) 'version': version,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +128,7 @@ class _DictionaryHitImpl extends DictionaryHit {
|
|||
String? reading,
|
||||
required List<String> labels,
|
||||
required String entry,
|
||||
String? version,
|
||||
}) : super._(
|
||||
source: source,
|
||||
sourceId: sourceId,
|
||||
|
|
@ -125,6 +136,7 @@ class _DictionaryHitImpl extends DictionaryHit {
|
|||
reading: reading,
|
||||
labels: labels,
|
||||
entry: entry,
|
||||
version: version,
|
||||
);
|
||||
|
||||
/// Returns a shallow copy of this [DictionaryHit]
|
||||
|
|
@ -138,6 +150,7 @@ class _DictionaryHitImpl extends DictionaryHit {
|
|||
Object? reading = _Undefined,
|
||||
List<String>? labels,
|
||||
String? entry,
|
||||
Object? version = _Undefined,
|
||||
}) {
|
||||
return DictionaryHit(
|
||||
source: source ?? this.source,
|
||||
|
|
@ -146,6 +159,7 @@ class _DictionaryHitImpl extends DictionaryHit {
|
|||
reading: reading is String? ? reading : this.reading,
|
||||
labels: labels ?? this.labels.map((e0) => e0).toList(),
|
||||
entry: entry ?? this.entry,
|
||||
version: version is String? ? version : this.version,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2208,6 +2208,12 @@ class Protocol extends _isd.DatabaseSerializationManager {
|
|||
.toList()
|
||||
as T;
|
||||
}
|
||||
if (t == Map<String, String>) {
|
||||
return (data as Map).map(
|
||||
(k, v) => MapEntry(deserialize<String>(k), deserialize<String>(v)),
|
||||
)
|
||||
as T;
|
||||
}
|
||||
try {
|
||||
return _iaic.Protocol().deserialize<T>(data, t);
|
||||
} on _isc.DeserializationTypeNotFoundException catch (_) {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue