Skip to content

Commit d388842

Browse files
committed
Significantly improve signin speed
1 parent f015998 commit d388842

5 files changed

Lines changed: 42 additions & 10 deletions

File tree

OpenFlow/src/Logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Logger {
3030
});
3131
options.console.format = winston.format.combine(
3232
winston.format.errors({ stack: true }),
33-
winston.format.timestamp({ format: 'HH:mm:ss' }),
33+
winston.format.timestamp({ format: 'HH:mm:ss.sss' }),
3434
winston.format.colorize(),
3535
winston.format.json(),
3636
myFormat
@@ -40,7 +40,7 @@ export class Logger {
4040
//format: winston.format.json(),
4141
format: winston.format.combine(
4242
winston.format.errors({ stack: true }),
43-
winston.format.timestamp({ format: 'HH:mm:ss' }),
43+
winston.format.timestamp({ format: 'HH:mm:ss.sss' }),
4444
winston.format.json(),
4545
myFormat
4646
),

OpenFlow/src/Messages/Message.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,32 @@ export class Message {
742742
}
743743
return tuser;
744744
}
745+
private async Signin2(cli: WebSocketServerClient): Promise<void> {
746+
this.Reply();
747+
let msg: SigninMessage
748+
let impostor: string = "";
749+
try {
750+
} catch (error) {
751+
if (NoderedUtil.IsNullUndefinded(msg)) { (msg as any) = {}; }
752+
if (msg !== null && msg !== undefined) msg.error = error.message ? error.message : error;
753+
cli._logger.error(error);
754+
}
755+
try {
756+
msg.websocket_package_size = Config.websocket_package_size;
757+
this.data = JSON.stringify(msg);
758+
} catch (error) {
759+
this.data = "";
760+
cli._logger.error(error);
761+
}
762+
this.Send(cli);
763+
}
745764
private async Signin(cli: WebSocketServerClient): Promise<void> {
746765
this.Reply();
766+
const hrstart = process.hrtime()
767+
let hrend = process.hrtime(hrstart)
747768
let msg: SigninMessage
748769
let impostor: string = "";
770+
const UpdateDoc: any = { "$set": {} };
749771
try {
750772
msg = SigninMessage.assign(this.data);
751773
let tuser: TokenUser = null;
@@ -806,6 +828,7 @@ export class Message {
806828
} else {
807829
if (msg.impersonate == "-1" || msg.impersonate == "false") {
808830
user = await DBHelper.FindById(impostor, Crypt.rootToken());
831+
UpdateDoc.$set["impersonating"] = undefined;
809832
user.impersonating = undefined;
810833
tuser = TokenUser.From(user);
811834
msg.impersonate = undefined;
@@ -818,7 +841,6 @@ export class Message {
818841
} else {
819842
msg.jwt = Crypt.createToken(tuser, Config.shorttoken_expires_in);
820843
}
821-
822844
msg.user = tuser;
823845
if (!NoderedUtil.IsNullEmpty(user.impersonating) && NoderedUtil.IsNullEmpty(msg.impersonate)) {
824846
const items = await Config.db.query({ _id: user.impersonating }, null, 1, 0, null, "users", msg.jwt);
@@ -870,18 +892,19 @@ export class Message {
870892
Audit.ImpersonateSuccess(tuser, tuserimpostor, cli.clientagent, cli.clientversion);
871893
}
872894
if (msg.firebasetoken != null && msg.firebasetoken != undefined && msg.firebasetoken != "") {
895+
UpdateDoc.$set["firebasetoken"] = msg.firebasetoken;
873896
user.firebasetoken = msg.firebasetoken;
874897
}
875898
if (msg.onesignalid != null && msg.onesignalid != undefined && msg.onesignalid != "") {
899+
UpdateDoc.$set["onesignalid"] = msg.onesignalid;
876900
user.onesignalid = msg.onesignalid;
877901
}
878-
if ((msg.onesignalid != null && msg.onesignalid != undefined && msg.onesignalid != "") ||
879-
(msg.onesignalid != null && msg.onesignalid != undefined && msg.onesignalid != "")) {
880-
}
881902
if (msg.gpslocation != null && msg.gpslocation != undefined && msg.gpslocation != "") {
903+
UpdateDoc.$set["gpslocation"] = msg.gpslocation;
882904
user.gpslocation = msg.gpslocation;
883905
}
884906
if (msg.device != null && msg.device != undefined && msg.device != "") {
907+
UpdateDoc.$set["device"] = msg.device;
885908
user.device = msg.device;
886909
}
887910
if (msg.validate_only !== true) {
@@ -893,20 +916,27 @@ export class Message {
893916
}
894917
if (msg.impersonate === undefined || msg.impersonate === null || msg.impersonate === "") {
895918
user.lastseen = new Date(new Date().toISOString());
919+
UpdateDoc.$set["lastseen"] = user.lastseen;
896920
}
897921
msg.supports_watch = Config.supports_watch;
898922
user._lastclientagent = cli.clientagent;
923+
UpdateDoc.$set["clientagent"] = cli.clientagent;
899924
user._lastclientversion = cli.clientversion;
925+
UpdateDoc.$set["clientversion"] = cli.clientversion;
900926
if (cli.clientagent == "openrpa") {
901927
user._lastopenrpaclientversion = cli.clientversion;
928+
UpdateDoc.$set["_lastopenrpaclientversion"] = cli.clientversion;
902929
}
903930
if (cli.clientagent == "nodered") {
904931
user._lastnoderedclientversion = cli.clientversion;
932+
UpdateDoc.$set["_lastnoderedclientversion"] = cli.clientversion;
905933
}
906934
if (cli.clientagent == "powershell") {
907935
user._lastpowershellclientversion = cli.clientversion;
936+
UpdateDoc.$set["_lastpowershellclientversion"] = cli.clientversion;
908937
}
909-
await DBHelper.Save(user, Crypt.rootToken());
938+
// await DBHelper.Save(user, Crypt.rootToken());
939+
await Config.db._UpdateOne({ "_id": user._id }, UpdateDoc, "users", 1, false, Crypt.rootToken())
910940
}
911941
} catch (error) {
912942
if (NoderedUtil.IsNullUndefinded(msg)) { (msg as any) = {}; }
@@ -920,6 +950,8 @@ export class Message {
920950
this.data = "";
921951
cli._logger.error(error);
922952
}
953+
hrend = process.hrtime(hrstart)
954+
console.log(`[Signin Completed] Execution time:${(hrend[0] * 1000000000 + hrend[1]) / 1000000} ms`)
923955
this.Send(cli);
924956
}
925957
private async RegisterUser(cli: WebSocketServerClient): Promise<void> {

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.1.151",
3+
"version": "1.1.152",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.151
1+
1.1.152

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.1.151",
3+
"version": "1.1.152",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)