Skip to content
Snippets Groups Projects
Commit 48a04866 authored by poka's avatar poka
Browse files

Improve search compute

parent 616801e6
No related branches found
No related tags found
No related merge requests found
Pipeline #14190 waiting for manual action
...@@ -2,6 +2,7 @@ import 'dart:io'; ...@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/chest_data.dart';
import 'package:gecko/models/g1_wallets_list.dart'; import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/g1_wallets_list_live.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
...@@ -18,6 +19,7 @@ Box<WalletData> walletBox; ...@@ -18,6 +19,7 @@ Box<WalletData> walletBox;
Box<ChestData> chestBox; Box<ChestData> chestBox;
Box configBox; Box configBox;
Box<G1WalletsList> g1WalletsBox; Box<G1WalletsList> g1WalletsBox;
Box<G1WalletsListLive> g1WalletsBoxLive;
String cesiumPod = "https://g1.data.le-sou.org"; String cesiumPod = "https://g1.data.le-sou.org";
// String cesiumPod = "https://g1.data.e-is.pro"; // String cesiumPod = "https://g1.data.e-is.pro";
......
...@@ -24,6 +24,7 @@ import 'package:gecko/models/change_pin.dart'; ...@@ -24,6 +24,7 @@ import 'package:gecko/models/change_pin.dart';
import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/chest_data.dart';
import 'package:gecko/models/chest_provider.dart'; import 'package:gecko/models/chest_provider.dart';
import 'package:gecko/models/g1_wallets_list.dart'; import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/g1_wallets_list_live.dart';
import 'package:gecko/models/generate_wallets.dart'; import 'package:gecko/models/generate_wallets.dart';
import 'package:gecko/models/history.dart'; import 'package:gecko/models/history.dart';
import 'package:gecko/models/home.dart'; import 'package:gecko/models/home.dart';
...@@ -61,10 +62,19 @@ Future<void> main() async { ...@@ -61,10 +62,19 @@ Future<void> main() async {
Hive.registerAdapter(ChestDataAdapter()); Hive.registerAdapter(ChestDataAdapter());
Hive.registerAdapter(G1WalletsListAdapter()); Hive.registerAdapter(G1WalletsListAdapter());
Hive.registerAdapter(IdAdapter()); Hive.registerAdapter(IdAdapter());
Hive.registerAdapter(G1WalletsListLiveAdapter());
Hive.registerAdapter(DataAdapter());
Hive.registerAdapter(WalletsAdapter());
Hive.registerAdapter(EdgesAdapter());
Hive.registerAdapter(NodeAdapter());
Hive.registerAdapter(BalanceAdapter());
Hive.registerAdapter(IdtyAdapter());
Hive.registerAdapter(PageInfoAdapter());
walletBox = await Hive.openBox<WalletData>("walletBox"); walletBox = await Hive.openBox<WalletData>("walletBox");
chestBox = await Hive.openBox<ChestData>("chestBox"); chestBox = await Hive.openBox<ChestData>("chestBox");
configBox = await Hive.openBox("configBox"); configBox = await Hive.openBox("configBox");
g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox"); g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox");
g1WalletsBoxLive = await Hive.openBox<G1WalletsListLive>("g1WalletsBoxLive");
// final HiveStore _store = // final HiveStore _store =
// await HiveStore.open(path: '${appPath.path}/gqlCache'); // await HiveStore.open(path: '${appPath.path}/gqlCache');
......
...@@ -8,7 +8,6 @@ import 'package:path_provider/path_provider.dart'; ...@@ -8,7 +8,6 @@ import 'package:path_provider/path_provider.dart';
class CesiumPlusProvider with ChangeNotifier { class CesiumPlusProvider with ChangeNotifier {
TextEditingController cesiumName = TextEditingController(); TextEditingController cesiumName = TextEditingController();
int iAvatar = 0;
bool isComplete = false; bool isComplete = false;
Future<List> _buildQuery(_pubkey) async { Future<List> _buildQuery(_pubkey) async {
...@@ -95,9 +94,8 @@ class CesiumPlusProvider with ChangeNotifier { ...@@ -95,9 +94,8 @@ class CesiumPlusProvider with ChangeNotifier {
responseJson['hits']['hits'][0]['_source']['avatar']['_content']; responseJson['hits']['hits'][0]['_source']['avatar']['_content'];
var avatarFile = var avatarFile =
File('${(await getTemporaryDirectory()).path}/avatar$iAvatar.png'); File('${(await getTemporaryDirectory()).path}/avatar_$_pubkey.png');
await avatarFile.writeAsBytes(base64.decode(_avatar)); await avatarFile.writeAsBytes(base64.decode(_avatar));
iAvatar++;
isComplete = true; isComplete = true;
return [avatarFile]; return [avatarFile];
......
import 'package:hive_flutter/hive_flutter.dart';
part 'g1_wallets_list_live.g.dart';
@HiveType(typeId: 4)
class G1WalletsListLive {
@HiveField(0)
Data data;
G1WalletsListLive({this.data});
G1WalletsListLive.fromJson(Map<String, dynamic> json) {
data = json['data'] != null ? Data.fromJson(json['data']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (this.data != null) {
data['data'] = this.data.toJson();
}
return data;
}
}
@HiveType(typeId: 5)
class Data {
Wallets wallets;
Data({this.wallets});
Data.fromJson(Map<String, dynamic> json) {
wallets =
json['wallets'] != null ? Wallets.fromJson(json['wallets']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (wallets != null) {
data['wallets'] = wallets.toJson();
}
return data;
}
}
@HiveType(typeId: 6)
class Wallets {
List<Edges> edges;
PageInfo pageInfo;
Wallets({this.edges, this.pageInfo});
Wallets.fromJson(Map<String, dynamic> json) {
if (json['edges'] != null) {
edges = <Edges>[];
json['edges'].forEach((v) {
edges.add(Edges.fromJson(v));
});
}
pageInfo =
json['pageInfo'] != null ? PageInfo.fromJson(json['pageInfo']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (edges != null) {
data['edges'] = edges.map((v) => v.toJson()).toList();
}
if (pageInfo != null) {
data['pageInfo'] = pageInfo.toJson();
}
return data;
}
}
@HiveType(typeId: 7)
class Edges {
Node node;
Edges({this.node});
Edges.fromJson(Map<String, dynamic> json) {
node = json['node'] != null ? Node.fromJson(json['node']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (node != null) {
data['node'] = node.toJson();
}
return data;
}
}
@HiveType(typeId: 8)
class Node {
Balance balance;
Idty idty;
String script;
Node({this.balance, this.idty, this.script});
Node.fromJson(Map<String, dynamic> json) {
balance =
json['balance'] != null ? Balance.fromJson(json['balance']) : null;
idty = json['idty'] != null ? Idty.fromJson(json['idty']) : null;
script = json['script'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (balance != null) {
data['balance'] = balance.toJson();
}
if (idty != null) {
data['idty'] = idty.toJson();
}
data['script'] = script;
return data;
}
}
@HiveType(typeId: 9)
class Balance {
int amount;
int base;
Balance({this.amount, this.base});
Balance.fromJson(Map<String, dynamic> json) {
amount = json['amount'];
base = json['base'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['amount'] = amount;
data['base'] = base;
return data;
}
}
@HiveType(typeId: 10)
class Idty {
bool isMember;
String username;
Idty({this.isMember, this.username});
Idty.fromJson(Map<String, dynamic> json) {
isMember = json['isMember'];
username = json['username'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['isMember'] = isMember;
data['username'] = username;
return data;
}
}
@HiveType(typeId: 11)
class PageInfo {
String endCursor;
bool hasNextPage;
PageInfo({this.endCursor, this.hasNextPage});
PageInfo.fromJson(Map<String, dynamic> json) {
endCursor = json['endCursor'];
hasNextPage = json['hasNextPage'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['endCursor'] = endCursor;
data['hasNextPage'] = hasNextPage;
return data;
}
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'g1_wallets_list_live.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class G1WalletsListLiveAdapter extends TypeAdapter<G1WalletsListLive> {
@override
final int typeId = 4;
@override
G1WalletsListLive read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return G1WalletsListLive(
data: fields[0] as Data,
);
}
@override
void write(BinaryWriter writer, G1WalletsListLive obj) {
writer
..writeByte(1)
..writeByte(0)
..write(obj.data);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is G1WalletsListLiveAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class DataAdapter extends TypeAdapter<Data> {
@override
final int typeId = 5;
@override
Data read(BinaryReader reader) {
return Data();
}
@override
void write(BinaryWriter writer, Data obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DataAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class WalletsAdapter extends TypeAdapter<Wallets> {
@override
final int typeId = 6;
@override
Wallets read(BinaryReader reader) {
return Wallets();
}
@override
void write(BinaryWriter writer, Wallets obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is WalletsAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class EdgesAdapter extends TypeAdapter<Edges> {
@override
final int typeId = 7;
@override
Edges read(BinaryReader reader) {
return Edges();
}
@override
void write(BinaryWriter writer, Edges obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is EdgesAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class NodeAdapter extends TypeAdapter<Node> {
@override
final int typeId = 8;
@override
Node read(BinaryReader reader) {
return Node();
}
@override
void write(BinaryWriter writer, Node obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NodeAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class BalanceAdapter extends TypeAdapter<Balance> {
@override
final int typeId = 9;
@override
Balance read(BinaryReader reader) {
return Balance();
}
@override
void write(BinaryWriter writer, Balance obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is BalanceAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class IdtyAdapter extends TypeAdapter<Idty> {
@override
final int typeId = 10;
@override
Idty read(BinaryReader reader) {
return Idty();
}
@override
void write(BinaryWriter writer, Idty obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is IdtyAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class PageInfoAdapter extends TypeAdapter<PageInfo> {
@override
final int typeId = 11;
@override
PageInfo read(BinaryReader reader) {
return PageInfo();
}
@override
void write(BinaryWriter writer, PageInfo obj) {
writer.writeByte(0);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PageInfoAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
...@@ -3,12 +3,13 @@ import 'package:flutter/foundation.dart'; ...@@ -3,12 +3,13 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:gecko/models/g1_wallets_list.dart'; import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/g1_wallets_list_live.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
class SearchProvider with ChangeNotifier { class SearchProvider with ChangeNotifier {
TextEditingController searchController = TextEditingController(); TextEditingController searchController = TextEditingController();
List searchResult = []; List searchResult = [];
final cacheDuring = 60 * 60 * 1000; //First number is minutes final cacheDuring = 0 * 60 * 1000; //First number is minutes
int cacheTime = 0; int cacheTime = 0;
void rebuildWidget() { void rebuildWidget() {
...@@ -20,15 +21,13 @@ class SearchProvider with ChangeNotifier { ...@@ -20,15 +21,13 @@ class SearchProvider with ChangeNotifier {
int searchTime = DateTime.now().millisecondsSinceEpoch; int searchTime = DateTime.now().millisecondsSinceEpoch;
if (cacheTime + cacheDuring <= searchTime) { if (cacheTime + cacheDuring <= searchTime) {
var url = Uri.parse('https://g1-stats.axiom-team.fr/data/forbes.json'); g1WalletsBox.clear();
var response = await http.get(url); final url = Uri.parse('https://g1-stats.axiom-team.fr/data/forbes.json');
// print('Response body: ${response.body}'); final response = await http.get(url);
List<G1WalletsList> _listWallets =
await compute(_parseG1Wallets, response.body);
for (G1WalletsList element in _listWallets) { List<G1WalletsList> _listWallets = _parseG1Wallets(response.body);
await g1WalletsBox.put(element.pubkey, element);
} await g1WalletsBox.addAll(_listWallets);
cacheTime = DateTime.now().millisecondsSinceEpoch; cacheTime = DateTime.now().millisecondsSinceEpoch;
} }
...@@ -43,12 +42,45 @@ class SearchProvider with ChangeNotifier { ...@@ -43,12 +42,45 @@ class SearchProvider with ChangeNotifier {
}); });
return searchResult; return searchResult;
}
Future<List> searchBlockchainLive() async {
searchResult.clear();
int searchTime = DateTime.now().millisecondsSinceEpoch;
if (cacheTime + cacheDuring <= searchTime) {
g1WalletsBox.clear();
final url = Uri.parse(
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
final response = await http.get(url);
// log.d(response.body);
// notifyListeners(); G1WalletsListLive _jsonResponse =
G1WalletsListLive.fromJson(json.decode(response.body));
while (_jsonResponse.data.wallets.pageInfo.hasNextPage) {
var cursor = _jsonResponse.data.wallets.pageInfo.endCursor;
final url = Uri.parse(
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
final response = await http.get(url);
}
// log.i(g1WalletsBox await configBox.put('g1WalletCache', _jsonResponse);
// .get('1N18iwCfzLYd7u6DTKafVrzs9bPyeYTGHoc5SsLMcfv') cacheTime = DateTime.now().millisecondsSinceEpoch;
// .balance); }
for (var value in configBox.get('g1WalletCache').data.wallets.edges) {
if ((value.node.idty != null &&
value.node.idty.username != null &&
value.node.idty.username.contains(searchController.text)) ||
value.node.script.contains(searchController.text)) {
searchResult.add(value);
}
}
// log.d(configBox.get('g1WalletCache').data.wallets.edges.toString());
return searchResult;
} }
} }
......
...@@ -23,7 +23,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -23,7 +23,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
// HistoryProvider _historyProvider; // HistoryProvider _historyProvider;
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
final FocusNode _pubkeyFocus = FocusNode(); final FocusNode _pubkeyFocus = FocusNode();
List cesiumData;
final double avatarsSize = 80; final double avatarsSize = 80;
FetchMore fetchMore; FetchMore fetchMore;
...@@ -199,7 +198,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -199,7 +198,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
], ],
builder: (BuildContext context, builder: (BuildContext context,
AsyncSnapshot<List> _avatar) { AsyncSnapshot<List> _avatar) {
cesiumData = _avatar.data;
// _cesiumPlusProvider.isComplete = true; // _cesiumPlusProvider.isComplete = true;
if (_avatar.connectionState != if (_avatar.connectionState !=
ConnectionState.done) { ConnectionState.done) {
...@@ -447,6 +445,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -447,6 +445,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
onTap: () { onTap: () {
// this._outputPubkey.text = repository[2]; // this._outputPubkey.text = repository[2];
_historyProvider.isPubkey(context, repository[2]); _historyProvider.isPubkey(context, repository[2]);
Navigator.pop(context);
}), }),
), ),
if (result.isLoading) if (result.isLoading)
......
import 'dart:io'; import 'dart:io';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -67,8 +66,9 @@ class SearchResultScreen extends StatelessWidget { ...@@ -67,8 +66,9 @@ class SearchResultScreen extends StatelessWidget {
const SizedBox(height: 20), const SizedBox(height: 20),
FutureBuilder( FutureBuilder(
future: _searchProvider.searchBlockchain(), future: _searchProvider.searchBlockchain(),
initialData: const [], // initialData: const [],
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Expanded( return Expanded(
child: ListView(children: <Widget>[ child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in snapshot.data) for (G1WalletsList g1Wallet in snapshot.data)
...@@ -129,7 +129,17 @@ class SearchResultScreen extends StatelessWidget { ...@@ -129,7 +129,17 @@ class SearchResultScreen extends StatelessWidget {
), ),
]), ]),
); );
}), }
return Center(
heightFactor: 5,
child: CircularProgressIndicator(
strokeWidth: 3,
backgroundColor: yellowC,
color: orangeC,
),
);
},
),
// Text( // Text(
// _searchProvider.searchResult.toString(), // _searchProvider.searchResult.toString(),
// ) // )
......
...@@ -544,6 +544,13 @@ packages: ...@@ -544,6 +544,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.1" version: "2.4.1"
infinite_scroll_pagination:
dependency: "direct main"
description:
name: infinite_scroll_pagination
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
integration_test: integration_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
...@@ -1002,6 +1009,13 @@ packages: ...@@ -1002,6 +1009,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.99" version: "0.0.99"
sliver_tools:
dependency: transitive
description:
name: sliver_tools
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
source_gen: source_gen:
dependency: transitive dependency: transitive
description: description:
......
...@@ -5,7 +5,7 @@ description: Pay with G1. ...@@ -5,7 +5,7 @@ description: Pay with G1.
# pub.dev using `pub publish`. This is preferred for private packages. # pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.3+5 version: 0.0.3+6
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"
...@@ -57,6 +57,7 @@ dependencies: ...@@ -57,6 +57,7 @@ dependencies:
carousel_slider: ^4.0.0 carousel_slider: ^4.0.0
flutter_lints: ^1.0.4 flutter_lints: ^1.0.4
confirm_dialog: ^1.0.0 confirm_dialog: ^1.0.0
infinite_scroll_pagination: ^3.1.0
flutter_icons: flutter_icons:
android: "ic_launcher" android: "ic_launcher"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment