From 2e14f8ff6ed7d91503700b2293588185512ce124 Mon Sep 17 00:00:00 2001 From: "Graciliano M. P." Date: Sun, 8 Nov 2026 18:36:27 -0300 Subject: [PATCH 1/2] Private cache fields: same-name memo fields take their getter's name again (v1.35.1) 1.35.0 renamed private memo fields to *Cache. A field that only memoizes a public getter or method of the same name (`_origin` for `origin`) takes that name again, as in 1.34.0: 27 fields. `_requesterAddressCache` is `_requesterAddressResolved` again (a value resolved once; the getter's name is taken by the given address). Caches filled by a private helper or a differently named member keep *Cache. Private names only. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 11 +++ lib/src/bones_api_base.dart | 22 ++--- lib/src/bones_api_entity.dart | 102 +++++++++++------------- lib/src/bones_api_entity_db_memory.dart | 14 ++-- lib/src/bones_api_entity_rules.dart | 20 ++--- lib/src/bones_api_sql_builder.dart | 35 ++++---- pubspec.yaml | 2 +- 7 files changed, 105 insertions(+), 101 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c3ef5e..96ac71c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 1.35.1 + +- Private fields that only memoize a public getter or method of the same + name (`String? _origin; String get origin => _origin ??= ...`) take that + name again, as before 1.35.0 renamed them to `*Cache`: 27 fields (e.g. + `_hostname`, `_port`, `_origin`, `_lastPathPart`, `_fieldsNames`, + `_fieldsWithTypeEntity`, `_totalRules`, `_tablesVersions`), and + `APIRequest._requesterAddressResolved` (its getter's name is taken by the + given address). Caches filled by a private helper or a differently named + member keep `*Cache`. Behavior unchanged (private names only). + ## 1.35.0 API/server layer clean-up (behavior-preserving): diff --git a/lib/src/bones_api_base.dart b/lib/src/bones_api_base.dart index d9aaa8f0..3b306479 100644 --- a/lib/src/bones_api_base.dart +++ b/lib/src/bones_api_base.dart @@ -52,7 +52,7 @@ typedef APILogger = void Function( /// Bones API Library class. class BonesAPI { // ignore: constant_identifier_names - static const String VERSION = '1.35.0'; + static const String VERSION = '1.35.1'; static bool _boot = false; @@ -2287,10 +2287,10 @@ class APIRequest extends APIMetricSet with APIPayload { /// A cache of [lastPathPart]: the request's path doesn't change, and the /// last path part is read on every routing of the request. - String? _lastPathPartCache; + String? _lastPathPart; /// Returns the last [pathParts]. Sames as [pathPartReversed] for index `0`. - String get lastPathPart => _lastPathPartCache ??= pathPartReversed(0); + String get lastPathPart => _lastPathPart ??= pathPartReversed(0); /// Returns from [parameters] a value for [name1]. Defaults to [def] if defined. V? getParameter(String name1, [V? def]) { @@ -2521,9 +2521,9 @@ class APIRequest extends APIMetricSet with APIPayload { /// Cache of [hostname], parsed from the `Host` header by [_hostnameImpl] /// on first read (the headers don't change during the request). - String? _hostnameCache; + String? _hostname; - String get hostname => _hostnameCache ??= _hostnameImpl(); + String get hostname => _hostname ??= _hostnameImpl(); String _hostnameImpl() { var host = getHeader('host'); @@ -2547,9 +2547,9 @@ class APIRequest extends APIMetricSet with APIPayload { /// Cache of [port], parsed from the `Port`/`Host` headers by [_portImpl] /// on first read. - int? _portCache; + int? _port; - int get port => _portCache ??= _portImpl(); + int get port => _port ??= _portImpl(); int _portImpl() { var port = getHeader('port'); @@ -2578,10 +2578,10 @@ class APIRequest extends APIMetricSet with APIPayload { /// Cache of [requesterAddress], resolved by [_requesterAddressImpl] /// (the given address, or the `X-Forwarded-For`/`Remote-Address` /// headers). A `null` result isn't cached (it's re-resolved on each read). - String? _requesterAddressCache; + String? _requesterAddressResolved; String? get requesterAddress => - _requesterAddressCache ??= _requesterAddressImpl(); + _requesterAddressResolved ??= _requesterAddressImpl(); String? _requesterAddressImpl() { if (_requesterAddress != null) return _requesterAddress; @@ -2606,9 +2606,9 @@ class APIRequest extends APIMetricSet with APIPayload { /// Cache of [origin], resolved by [_originImpl] (the `Origin` header, or /// built from [scheme] and [hostnameAndPort]) on first read. - String? _originCache; + String? _origin; - String get origin => _originCache ??= _originImpl(); + String get origin => _origin ??= _originImpl(); String _originImpl() { var origin = getHeader('origin'); diff --git a/lib/src/bones_api_entity.dart b/lib/src/bones_api_entity.dart index 3a62d206..0541bf96 100644 --- a/lib/src/bones_api_entity.dart +++ b/lib/src/bones_api_entity.dart @@ -568,9 +568,9 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { /// Cache of [idType]: the [Type] of the ID field, fixed per entity type /// and looked up on every ID parse/compare. - Type? _idTypeCache; + Type? _idType; - Type idType([O? o]) => _idTypeCache ??= getFieldType( + Type idType([O? o]) => _idType ??= getFieldType( o, idFieldName(o), resolveFiledName: false, @@ -586,20 +586,17 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { // The fields of an entity type are fixed, so each filter runs once. /// Cache of [fieldsWithTypeList]: the fields of a `List` type. - Map? _fieldsWithTypeListCache; + Map? _fieldsWithTypeList; - Map fieldsWithTypeList([O? o]) => - _fieldsWithTypeListCache ??= fieldsWithType( - (_, fieldType) => fieldType.isList, - o, - ); + Map fieldsWithTypeList([O? o]) => _fieldsWithTypeList ??= + fieldsWithType((_, fieldType) => fieldType.isList, o); /// Cache of [fieldsWithTypeEntity]: the fields holding an entity /// (not an [EntityReference]). - Map? _fieldsWithTypeEntityCache; + Map? _fieldsWithTypeEntity; Map fieldsWithTypeEntity([O? o]) => - _fieldsWithTypeEntityCache ??= fieldsWithType( + _fieldsWithTypeEntity ??= fieldsWithType( (_, fieldType) => !fieldType.isBasicType && !fieldType.isEntityReferenceListType && @@ -610,10 +607,10 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { /// Cache of [fieldsWithTypeEntityOrReference]: the fields holding an /// entity or an [EntityReference]. - Map? _fieldsWithTypeEntityOrReferenceCache; + Map? _fieldsWithTypeEntityOrReference; Map fieldsWithTypeEntityOrReference([O? o]) => - _fieldsWithTypeEntityOrReferenceCache ??= fieldsWithType( + _fieldsWithTypeEntityOrReference ??= fieldsWithType( (_, fieldType) => (!fieldType.isBasicType && !fieldType.isEntityReferenceListType && @@ -625,20 +622,20 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { /// Cache of [fieldsWithEntityReference]: the fields of an /// [EntityReference] type. - Map? _fieldsWithEntityReferenceCache; + Map? _fieldsWithEntityReference; Map fieldsWithEntityReference([O? o]) => - _fieldsWithEntityReferenceCache ??= Map.unmodifiable( + _fieldsWithEntityReference ??= Map.unmodifiable( fieldsWithTypeEntityOrReference(o).entries .where((e) => e.value.isEntityReferenceType) .toMapFromEntries(), ); /// Cache of [fieldsWithTypeListEntity]: the fields of a list of entities. - Map? _fieldsWithTypeListEntityCache; + Map? _fieldsWithTypeListEntity; Map fieldsWithTypeListEntity([O? o]) => - _fieldsWithTypeListEntityCache ??= fieldsWithType( + _fieldsWithTypeListEntity ??= fieldsWithType( (_, fieldType) => fieldType.isValidListEntityType, o, ); @@ -668,23 +665,22 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { /// Cache of [fieldsWithEntityReferenceList]: the (non-hidden) fields of an /// [EntityReferenceList] type. - Map? _fieldsWithEntityReferenceListCache; + Map? _fieldsWithEntityReferenceList; Map fieldsWithEntityReferenceList([O? o]) => - _fieldsWithEntityReferenceListCache ??= - Map.unmodifiable( - fieldsWithTypeListEntityOrReference(o).entries - .where((e) => e.value.isEntityReferenceListType) - .toMapFromEntries(), - ); + _fieldsWithEntityReferenceList ??= Map.unmodifiable( + fieldsWithTypeListEntityOrReference(o).entries + .where((e) => e.value.isEntityReferenceListType) + .toMapFromEntries(), + ); /// Cache of [fieldsEntityAnnotations] (also filled by subclasses): /// field name -> its unmodifiable [EntityAnnotation]s. Built once (fixed /// fields; a reflection lookup per field). - Map>? _fieldsEntityAnnotationsCache; + Map>? _fieldsEntityAnnotations; Map> fieldsEntityAnnotations() => - _fieldsEntityAnnotationsCache ??= + _fieldsEntityAnnotations ??= Map>.unmodifiable( (getAllFieldsEntityAnnotations() ?? {}) .map>( @@ -1614,25 +1610,25 @@ abstract class EntityHandler with FieldsFromMap, EntityRulesResolver { /// Cache of [fieldsNamesIndexes]: field name -> index in [fieldsNames]. /// The fields of an entity type are fixed, so it's built once. - Map? _fieldsNamesIndexesCache; + Map? _fieldsNamesIndexes; Map fieldsNamesIndexes([O? o]) => - _fieldsNamesIndexesCache ??= buildFieldsNamesIndexes(fieldsNames(o)); + _fieldsNamesIndexes ??= buildFieldsNamesIndexes(fieldsNames(o)); /// Cache of [fieldsNamesLC]: the [fieldsNames] in lower case, used for /// case-insensitive field lookups. Built once (fixed fields). - List? _fieldsNamesLCCache; + List? _fieldsNamesLC; List fieldsNamesLC([O? o]) => - _fieldsNamesLCCache ??= buildFieldsNamesLC(fieldsNames(o)); + _fieldsNamesLC ??= buildFieldsNamesLC(fieldsNames(o)); /// Cache of [fieldsNamesSimple]: the [fieldsNames] as simple keys /// (`fieldToSimpleKey`), used for lenient field lookups. Built once (fixed /// fields). - List? _fieldsNamesSimpleCache; + List? _fieldsNamesSimple; List fieldsNamesSimple([O? o]) => - _fieldsNamesSimpleCache ??= buildFieldsNamesSimple(fieldsNames(o)); + _fieldsNamesSimple ??= buildFieldsNamesSimple(fieldsNames(o)); TypeInfo? getFieldType(O? o, String key, {bool resolveFiledName = false}); @@ -2907,7 +2903,7 @@ class GenericEntityHandler extends EntityHandler { String? _idFieldNameCache; /// Cache of [fieldsNames], filled by [inspectObject]. - List? _fieldsNamesCache; + List? _fieldsNames; @override String idFieldName([O? o]) => _inspectedOrThrow( @@ -2921,7 +2917,7 @@ class GenericEntityHandler extends EntityHandler { @override List fieldsNames([O? o]) => _inspectedOrThrow( o, - () => _fieldsNamesCache, + () => _fieldsNames, () => "`fieldsNames` Not populated yet! No Entity instance presented to this EntityHandler yet. Type: $type", ); @@ -2971,7 +2967,7 @@ class GenericEntityHandler extends EntityHandler { if (o != null && _idFieldNameCache == null) { _idFieldNameCache = o.idFieldName; - final fieldsNames = _fieldsNamesCache ??= List.unmodifiable( + final fieldsNames = _fieldsNames ??= List.unmodifiable( o.fieldsNames, ); @@ -2981,7 +2977,7 @@ class GenericEntityHandler extends EntityHandler { ), ); - _fieldsEntityAnnotationsCache ??= + _fieldsEntityAnnotations ??= Map>.unmodifiable( Map>.fromEntries( fieldsNames.map((f) { @@ -3089,7 +3085,7 @@ class GenericEntityHandler extends EntityHandler { if (o != null) { return o.getFieldEntityAnnotations(key); } else { - return _fieldsEntityAnnotationsCache?[key]; + return _fieldsEntityAnnotations?[key]; } } @@ -3141,10 +3137,10 @@ class ClassReflectionEntityHandler extends EntityHandler { /// Cache of [siblingsEntityHandlers]: the handlers of the sibling classes /// (same reflection bundle), fixed after the reflection is registered. - List? _siblingsEntityHandlersCache; + List? _siblingsEntityHandlers; List siblingsEntityHandlers() => - _siblingsEntityHandlersCache ??= + _siblingsEntityHandlers ??= List.unmodifiable( reflection.siblingsClassReflection().map((c) => c.entityHandler), ); @@ -3343,7 +3339,7 @@ class ClassReflectionEntityHandler extends EntityHandler { if (idFieldName != null) return idFieldName; // Just to populate: - if (_fieldsNamesCache == null) { + if (_fieldsNames == null) { fieldsNames(o); } @@ -3403,11 +3399,11 @@ class ClassReflectionEntityHandler extends EntityHandler { } /// Cache of [fieldsNames]: the keys of [fieldsTypes] (fixed per class). - List? _fieldsNamesCache; + List? _fieldsNames; @override List fieldsNames([O? o]) => - _fieldsNamesCache ??= List.unmodifiable(fieldsTypes(o).keys); + _fieldsNames ??= List.unmodifiable(fieldsTypes(o).keys); @override Map fieldsTypes([O? o]) { @@ -3426,23 +3422,19 @@ class ClassReflectionEntityHandler extends EntityHandler { /// Cache of [constructors]: constructor name -> its parameters' types. /// Fixed per class, and a full reflection scan to build. - Map>? _constructorsCache; + Map>? _constructors; @override Map>? constructors([O? o]) { - return _constructorsCache ??= - Map>.unmodifiable( - reflectionWithObject(o).allConstructors().map((c) { - var name = c.name; - var args = c.allParameters - .map( - (p) => - MapEntry(p.jsonName, p.type.typeInfo), - ) - .toMapFromEntries(); - return MapEntry(name, Map.unmodifiable(args)); - }).toMapFromEntries(), - ); + return _constructors ??= Map>.unmodifiable( + reflectionWithObject(o).allConstructors().map((c) { + var name = c.name; + var args = c.allParameters + .map((p) => MapEntry(p.jsonName, p.type.typeInfo)) + .toMapFromEntries(); + return MapEntry(name, Map.unmodifiable(args)); + }).toMapFromEntries(), + ); } @override diff --git a/lib/src/bones_api_entity_db_memory.dart b/lib/src/bones_api_entity_db_memory.dart index ecb8a930..b2819240 100644 --- a/lib/src/bones_api_entity_db_memory.dart +++ b/lib/src/bones_api_entity_db_memory.dart @@ -238,8 +238,8 @@ class DBSQLMemoryAdapter extends DBSQLAdapter >>{}; void _onTablesModification() { - _tablesVersionsCache = null; - _tablesIndexesVersionsCache = null; + _tablesVersions = null; + _tablesIndexesVersions = null; } /// A cache of [tablesVersions], filled on its first call and reset by @@ -248,10 +248,10 @@ class DBSQLMemoryAdapter extends DBSQLAdapter /// Why: each new connection ([DBSQLMemoryAdapterContext]) snapshots the /// versions (to roll the tables back to them), usually more often than /// the tables change: the map isn't rebuilt for each one. - Map? _tablesVersionsCache; + Map? _tablesVersions; Map get tablesVersions => - _tablesVersionsCache ??= UnmodifiableMapView( + _tablesVersions ??= UnmodifiableMapView( _tables.map((table, map) => MapEntry(table, map.version)), ); @@ -616,11 +616,11 @@ class DBSQLMemoryAdapter extends DBSQLAdapter >>>{}; /// A cache of [tablesIndexesVersions], filled on its first call and reset - /// by [_onTablesModification]. As [_tablesVersionsCache]. - Map>? _tablesIndexesVersionsCache; + /// by [_onTablesModification]. As [_tablesVersions]. + Map>? _tablesIndexesVersions; Map> get tablesIndexesVersions => - _tablesIndexesVersionsCache ??= UnmodifiableMapView( + _tablesIndexesVersions ??= UnmodifiableMapView( _tablesIndexes.map( (table, fieldIndex) => MapEntry( table, diff --git a/lib/src/bones_api_entity_rules.dart b/lib/src/bones_api_entity_rules.dart index 78000519..36c358bd 100644 --- a/lib/src/bones_api_entity_rules.dart +++ b/lib/src/bones_api_entity_rules.dart @@ -782,10 +782,10 @@ class EntityAccessRulesCached implements EntityAccessRules { /// Cache of [totalRules]: the rule tree is immutable, so the count is /// computed (a full traversal) only once. - int? _totalRulesCache; + int? _totalRules; @override - int totalRules() => _totalRulesCache ??= accessRules.totalRules(); + int totalRules() => _totalRules ??= accessRules.totalRules(); @override bool? get _innocuous => accessRules._innocuous; @@ -828,20 +828,22 @@ class EntityAccessRulesCached implements EntityAccessRules { /// Cache of [hasRuleForEntityType] results by entity [Type]: called for /// every object encoded to JSON, and each call walks the rule tree. - final Map _hasRuleForEntityTypeCache = {}; + final Map _hasRuleForEntityType = {}; @override - bool hasRuleForEntityType(Type type) => _hasRuleForEntityTypeCache - .putIfAbsent(type, () => accessRules.hasRuleForEntityType(type)); + bool hasRuleForEntityType(Type type) => _hasRuleForEntityType.putIfAbsent( + type, + () => accessRules.hasRuleForEntityType(type), + ); /// Cache of [hasRuleType] results, keyed by the (element-wise compared) /// list of rule types queried: each call walks the rule tree. - final Map<_CacheKey, bool> _hasRuleTypeCache = <_CacheKey, bool>{}; + final Map<_CacheKey, bool> _hasRuleType = <_CacheKey, bool>{}; @override bool hasRuleType(List ruleTypes) { final cacheKey = _CacheKey(ruleTypes); - return _hasRuleTypeCache.putIfAbsent( + return _hasRuleType.putIfAbsent( cacheKey, () => accessRules.hasRuleType(ruleTypes), ); @@ -849,10 +851,10 @@ class EntityAccessRulesCached implements EntityAccessRules { /// Cache of [hasRuleForEntityTypeField] results by entity [Type]: called /// for every object encoded to JSON, and each call walks the rule tree. - final Map _hasRuleForEntityTypeFieldCache = {}; + final Map _hasRuleForEntityTypeField = {}; @override - bool hasRuleForEntityTypeField(Type type) => _hasRuleForEntityTypeFieldCache + bool hasRuleForEntityTypeField(Type type) => _hasRuleForEntityTypeField .putIfAbsent(type, () => accessRules.hasRuleForEntityTypeField(type)); @override diff --git a/lib/src/bones_api_sql_builder.dart b/lib/src/bones_api_sql_builder.dart index bd9eb5d2..8406a945 100644 --- a/lib/src/bones_api_sql_builder.dart +++ b/lib/src/bones_api_sql_builder.dart @@ -496,34 +496,33 @@ class CreateTableSQL extends TableSQL { /// Why: it's called repeatedly while sorting the tables by their /// dependencies, and it's derived from the [entries]. Reset by /// [_disposeCache]. - List? _referenceTablesCache; + List? _referenceTables; @override - List get referenceTables => _referenceTablesCache ??= { + List get referenceTables => _referenceTables ??= { ...entries.expand((e) => e.referenceTables ?? []), }.toList(); /// A cache of [relationshipsTables], filled on its first call. As - /// [_referenceTablesCache], derived from the [relationships]. Reset by + /// [_referenceTables], derived from the [relationships]. Reset by /// [_disposeCache]. - List? _relationshipsTablesCache; + List? _relationshipsTables; /// Returns the tables of the [relationships]. - List get relationshipsTables => - _relationshipsTablesCache ??= { - ...?relationships?.expand( - (e) => e.referenceTables.where((t) => t != table), - ), - }.toList(); + List get relationshipsTables => _relationshipsTables ??= { + ...?relationships?.expand( + (e) => e.referenceTables.where((t) => t != table), + ), + }.toList(); /// A cache of [referenceAndRelationshipTables] (the [dependentTables]), - /// filled on its first call. As [_referenceTablesCache]. Reset by + /// filled on its first call. As [_referenceTables]. Reset by /// [_disposeCache]. - List? _referenceAndRelationshipTablesCache; + List? _referenceAndRelationshipTables; /// Returns the tables in [referenceTables] and [relationshipsTables]. List get referenceAndRelationshipTables => - _referenceAndRelationshipTablesCache ??= { + _referenceAndRelationshipTables ??= { ...referenceTables, ...relationshipsTables, }.toList(); @@ -543,9 +542,9 @@ class CreateTableSQL extends TableSQL { entries.where((e) => e.type == 'CONSTRAINT').toList(); void _disposeCache() { - _referenceTablesCache = null; - _relationshipsTablesCache = null; - _referenceAndRelationshipTablesCache = null; + _referenceTables = null; + _relationshipsTables = null; + _referenceAndRelationshipTables = null; } /// Converts the [constraints] to [AlterTableSQL]. @@ -712,10 +711,10 @@ class AlterTableSQL extends TableSQL { /// /// Why: it's called repeatedly while sorting the tables by their /// dependencies, and it's derived from the [entries]. - List? _referenceTablesCache; + List? _referenceTables; @override - List get referenceTables => _referenceTablesCache ??= { + List get referenceTables => _referenceTables ??= { ...entries.expand((e) => e.referenceTables ?? []).nonNulls, }.toList(); diff --git a/pubspec.yaml b/pubspec.yaml index 29c0166b..1145dabb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_api description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters. -version: 1.35.0 +version: 1.35.1 homepage: https://github.com/Colossus-Services/bones_api environment: From f28ca7f0c6366a3228a5dd93a6af0cdec4ba5622 Mon Sep 17 00:00:00 2001 From: "Graciliano M. P." Date: Sun, 8 Nov 2026 18:41:15 -0300 Subject: [PATCH 2/2] sqlite3: ^3.9.1 (a failed download reports the HTTP error) sqlite3 3.9.1's build hook checks the response status of its native library download from GitHub releases: an outage (e.g. a 504) is reported as such, not as a hash mismatch (simolus3/sqlite3.dart#435). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ac71c7..cab39e1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ `APIRequest._requesterAddressResolved` (its getter's name is taken by the given address). Caches filled by a private helper or a differently named member keep `*Cache`. Behavior unchanged (private names only). +- `sqlite3: ^3.9.1` (was `^3.8.0`): its build hook now reports a failed + native-library download from GitHub releases as the HTTP error (e.g. + `504`), not as a hash mismatch (simolus3/sqlite3.dart#435). 3.9.0 also + added `CommonDatabase.trace` and `Database.interrupt()`. ## 1.35.0 diff --git a/pubspec.yaml b/pubspec.yaml index 1145dabb..e634d10e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: mime: ^2.1.0 postgres: ^3.5.20 mysql1: ^0.22.0 - sqlite3: ^3.8.0 + sqlite3: ^3.9.1 gcloud: ^0.9.0 yaml: ^3.1.4 crypto: ^3.0.8