mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-03-27 02:01:51 +01:00
reduced items fetched to reduce cpu use etc
fixed user count in relay which was undone few commits ago
This commit is contained in:
parent
922377a4e4
commit
a802e7bd1f
@ -236,9 +236,6 @@ Future<void> main(List<String> arguments) async {
|
||||
}
|
||||
|
||||
gEventsFilename = argResults[eventFileArg];
|
||||
if( gEventsFilename != "") {
|
||||
//print("Going to use ${whetherDefault}file to read from and store events: $gEventsFilename");
|
||||
}
|
||||
}
|
||||
|
||||
Set<Event> initialEvents = {}; // collect all events here and then create tree out of them
|
||||
@ -247,15 +244,27 @@ Future<void> main(List<String> arguments) async {
|
||||
stdout.write('Reading events from ${whetherDefault}file.......');
|
||||
|
||||
// read file events and give the events to relays from where they're picked up later
|
||||
//log.info("before reading events");
|
||||
initialEvents = await readEventsFromFile(gEventsFilename);
|
||||
//log.info("after reading events");
|
||||
|
||||
// count events
|
||||
initialEvents.forEach((element) { numFileEvents++;});
|
||||
print("read $numFileEvents events from file $gEventsFilename");
|
||||
}
|
||||
|
||||
int limitSelfEvents = 200;
|
||||
int limitOthersEvents = 4;
|
||||
int limitPerSubscription = gLimitPerSubscription;
|
||||
|
||||
// if more than 1000 posts have already been read from the file, then don't get too many day's events. Only for last 3 days.
|
||||
if(numFileEvents > 1000) {
|
||||
limitPerSubscription = 5000;
|
||||
limitSelfEvents = 10;
|
||||
limitOthersEvents = 3;
|
||||
gDefaultNumWaitSeconds = gDefaultNumWaitSeconds ~/5;
|
||||
} else {
|
||||
printInfoForNewUser();
|
||||
}
|
||||
|
||||
// process request string. If this is blank then the application only reads from file and does not connect to internet.
|
||||
if( argResults[requestArg] != null) {
|
||||
int numWaitSeconds = gDefaultNumWaitSeconds;
|
||||
@ -267,14 +276,18 @@ Future<void> main(List<String> arguments) async {
|
||||
numWaitSeconds = 0;
|
||||
gEventsFilename = ""; // so it wont write it back to keep it faster ( and since without internet no new event is there to be written )
|
||||
}
|
||||
|
||||
if( userPublicKey!= "") {
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents));
|
||||
getMentionEvents(gListRelayUrls1, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), "#p");
|
||||
}
|
||||
|
||||
Future.delayed(Duration(milliseconds: numWaitSeconds * 2), () {
|
||||
Future.delayed(Duration(milliseconds: numWaitSeconds), () {
|
||||
Set<Event> receivedEvents = getRecievedEvents();
|
||||
//stdout.write("received ${receivedEvents.length - numFilePosts} events\n");
|
||||
|
||||
initialEvents.addAll(receivedEvents);
|
||||
|
||||
// Creat tree from all events read form file
|
||||
// Create tree from all events read form file
|
||||
Store node = getTree(initialEvents);
|
||||
|
||||
clearEvents();
|
||||
@ -293,21 +306,6 @@ Future<void> main(List<String> arguments) async {
|
||||
// then get the events of user-id's mentioned in p-tags of received events and the contact list
|
||||
// then display them all
|
||||
|
||||
int limitSelfEvents = 300;
|
||||
int limitOthersEvents = 20;
|
||||
|
||||
int limitPerSubscription = gLimitPerSubscription;
|
||||
|
||||
// if more than 1000 posts have already been read from the file, then don't get too many day's events. Only for last 3 days.
|
||||
if(numFileEvents > 1000) {
|
||||
limitPerSubscription = 5000;
|
||||
limitSelfEvents = 10;
|
||||
limitOthersEvents = 3;
|
||||
gDefaultNumWaitSeconds = gDefaultNumWaitSeconds ~/5 ;
|
||||
} else {
|
||||
printInfoForNewUser();
|
||||
}
|
||||
|
||||
// get event for user
|
||||
if( userPublicKey!= "") {
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents));
|
||||
@ -319,7 +317,6 @@ Future<void> main(List<String> arguments) async {
|
||||
// remove user from default list if he exists in it. because theyv'e already been fetched.
|
||||
gDefaultFollows = gDefaultFollows.difference(usersFetched);
|
||||
|
||||
//print("getting defaultfollows. usersFetched len = ${usersFetched.length} ");
|
||||
// get other user events
|
||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 4 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents));
|
||||
usersFetched = usersFetched.union(gDefaultFollows);
|
||||
|
@ -8,7 +8,7 @@ import 'package:web_socket_channel/io.dart';
|
||||
class Relay {
|
||||
String url;
|
||||
IOWebSocketChannel socket;
|
||||
List<String> users; // is used so that duplicate requests aren't sent for same user for this same relay
|
||||
Set<String> users; // is used so that duplicate requests aren't sent for same user for this same relay
|
||||
int numReceived;
|
||||
int numRequestsSent;
|
||||
Relay(this.url, this.socket, this.users, this.numReceived, this.numRequestsSent);
|
||||
@ -40,7 +40,7 @@ class Relays {
|
||||
IOWebSocketChannel fws = IOWebSocketChannel.connect(relayUrl);
|
||||
print('In Relay.relay: connecting to relay $relayUrl');
|
||||
Map<String, Relay> mapRelay = {};
|
||||
Relay relayObject = Relay( relayUrl, fws, [], 0, 0);
|
||||
Relay relayObject = Relay( relayUrl, fws, {}, 0, 0);
|
||||
mapRelay[relayUrl] = relayObject;
|
||||
|
||||
return Relays(mapRelay, {}, {});
|
||||
@ -67,14 +67,19 @@ class Relays {
|
||||
|
||||
String subscriptionId = "single_user" + (relays[relayUrl]?.numRequestsSent??"").toString() + "_" + relayUrl.substring(6);
|
||||
if( relays.containsKey(relayUrl)) {
|
||||
List<String>? users = relays[relayUrl]?.users;
|
||||
Set<String>? users = relays[relayUrl]?.users;
|
||||
if( users != null) { // get a user only if it has not already been requested
|
||||
// following is too restrictive casuse changed sinceWhen is not considered. TODO improve it
|
||||
for(int i = 0; i < users.length; i++) {
|
||||
if( users[i] == publicKey) {
|
||||
return;
|
||||
bool alreadyRecevied = false;
|
||||
users.forEach((user) {
|
||||
if( user == publicKey) {
|
||||
alreadyRecevied = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if( alreadyRecevied)
|
||||
return;
|
||||
|
||||
users.add(publicKey);
|
||||
}
|
||||
}
|
||||
@ -104,9 +109,19 @@ class Relays {
|
||||
void getMultiUserEvents(String relayUrl, List<String> publicKeys, int limit, int sinceWhen, [Set<int>? kind = null]) {
|
||||
//print("In relays: getmulti events kind = $kind len ${publicKeys.length}");
|
||||
|
||||
Set<String> setPublicKeys = publicKeys.toSet();
|
||||
|
||||
if( relays.containsKey(relayUrl)) {
|
||||
Set<String>? users = relays[relayUrl]?.users;
|
||||
if( users != null) {
|
||||
relays[relayUrl]?.users = users.union(setPublicKeys);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
String subscriptionId = "multiple_user" + (relays[relayUrl]?.numRequestsSent??"").toString() + "_" + relayUrl.substring(6);
|
||||
|
||||
String request = getMultiUserRequest( subscriptionId, publicKeys.toSet(), limit, sinceWhen, kind);
|
||||
String request = getMultiUserRequest( subscriptionId, setPublicKeys, limit, sinceWhen, kind);
|
||||
sendRequest(relayUrl, request);
|
||||
}
|
||||
|
||||
@ -132,7 +147,7 @@ class Relays {
|
||||
|
||||
try {
|
||||
IOWebSocketChannel fws2 = IOWebSocketChannel.connect(relay);
|
||||
Relay newRelay = Relay(relay, fws2, [], 0, 1);
|
||||
Relay newRelay = Relay(relay, fws2, {}, 0, 1);
|
||||
relays[relay] = newRelay;
|
||||
fws = fws2;
|
||||
fws2.stream.listen(
|
||||
|
@ -11,6 +11,8 @@ homepage: https://github.com/vishalxl/nostr_console
|
||||
# fixed new issue of taking longer time when file was already there
|
||||
# increased channel fetches from 2 days from half a day
|
||||
|
||||
# reduced items fetched. 23/12
|
||||
|
||||
environment:
|
||||
sdk: '>=2.17.3 <3.0.0'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user