Skip to content

Commit

Permalink
Fix preset combo cache issue, and mark 5.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed May 27, 2024
1 parent 0f680f4 commit 2e90366
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 5.1

_Unreleased_
_Released on 2024-05-28_

* Added the recent walked path display as small blue dots.
* GeoScribbles drawing is locked by default.
Expand Down
4 changes: 2 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart' show Colors, TextStyle;

const kAppTitle = 'Every Door';
const kAppVersion = '5.1-beta2'; // Also used for presets.db versioning
const kAppVersion = '5.1'; // Also used for presets.db versioning

const kDefaultLocation = <double>[59.42, 24.71];
const kDatabaseName = 'every_door.db';
Expand Down Expand Up @@ -32,7 +32,7 @@ const kMaxNSIPresets = 3; // how many of them can come from NSI
const kFollowLinks = true; // whether to open links and phones on tap
const kUploadOnClose = false; // whether to trigger data upload on app deactivation
const kShowContactSetting = true; // whether to show the "contact:" setting
const kSlowDownGPS = false; // skip location changes that are too small to register
const kSlowDownGPS = true; // skip location changes that are too small to register
const kInitialZoom = 17.0; // For POI list screen
const kEditMinZoom = 15.0; // Below that, the navigation mode switches on
const kEditMaxZoom = 21.0; // Same for all modes
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/geolocation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GeolocationController extends StateNotifier<LatLng?> {
late DateTime _stateTime;

GeolocationController(this._ref) : super(null) {
_stateTime = DateTime.now();
_stateTime = DateTime.now().subtract(Duration(hours: 1));
_statSub = Geolocator.getServiceStatusStream().listen((status) {
if (status == ServiceStatus.enabled) {
enableTracking();
Expand Down
32 changes: 20 additions & 12 deletions lib/providers/presets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class PresetProvider {
// final unpacked = io.GZipCodec().decode(bytes);
await dbFile.writeAsBytes(bytes, flush: true);
prefs.setString(kDbVersion, kAppVersion);
await clearComboCache();
}

_db = await openDatabase(dbFile.path);
Expand Down Expand Up @@ -308,6 +309,11 @@ class PresetProvider {

static const kCachedCombosTableName = 'cached_combos';

Future<void> clearComboCache() async {
final database = await _ref.read(databaseProvider).database;
await database.delete(kCachedCombosTableName);
}

Future<void> _updateComboCache(String key, Iterable<String> options) async {
final database = await _ref.read(databaseProvider).database;
await database.insert(
Expand Down Expand Up @@ -474,18 +480,19 @@ class PresetProvider {
List<PresetField> moreFields = [];
final seenFields = <String>{};
for (final row in results) {
if (seenFields.contains(row['name'])) continue;
if (kSkipFields.contains(row['name'])) continue;
seenFields.add(row['name'] as String);
final name = row['name'] as String;
if (seenFields.contains(name)) continue;
if (kSkipFields.contains(name)) continue;
seenFields.add(name);

// Either build a field, or restore it from a cache.
PresetField field;
if (_fieldCache.containsKey(row['name'])) {
field = _fieldCache[row['name']]!;
if (_fieldCache.containsKey(name)) {
field = _fieldCache[name]!;
} else {
final options = await _getComboOptions(row);
field = fieldFromJson(row, options: options);
_fieldCache[row['name'] as String] = field;
_fieldCache[name] = field;
}

// Skip fields that don't fit the location.
Expand Down Expand Up @@ -551,20 +558,21 @@ class PresetProvider {
Map<String, PresetField> fields = {};
final seenFields = <String>{};
for (final row in results) {
if (seenFields.contains(row['name'])) continue;
seenFields.add(row['name'] as String);
final name = row['name'] as String;
if (seenFields.contains(name)) continue;
seenFields.add(name);

// Either build a field, or restore it from a cache.
PresetField field;
if (_fieldCache.containsKey(row['name'])) {
field = _fieldCache[row['name']]!;
if (_fieldCache.containsKey(name)) {
field = _fieldCache[name]!;
} else {
final options = await _getComboOptions(row);
field = fieldFromJson(row, options: options);
_fieldCache[row['name'] as String] = field;
_fieldCache[name] = field;
}

fields[row['name'] as String] = field;
fields[name] = field;
}
return fields;
}
Expand Down
4 changes: 4 additions & 0 deletions metadata/en-US/changelogs/45.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Added the recent walked path display.
* GeoScribbles drawing is locked by default.
* QR code scanner for the website field.
* Location is now updated once a second.
4 changes: 4 additions & 0 deletions metadata/ru/changelogs/45.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* выводим недавно пройденный маршрут;
* режим рисования изначально заблокирован;
* сканер QR-кодов для поля веб-сайта;
* координаты теперь обновляются ежесекундно.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Next generation OpenStreetMap amenity mapper
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# Also update version in constants.dart!
version: 5.0.2+44
version: 5.1.0+45

environment:
sdk: ">=3.3.0 <4.0.0"
Expand Down

0 comments on commit 2e90366

Please sign in to comment.