diff --git a/OpenFlow/src/Config.ts b/OpenFlow/src/Config.ts index 23f567b1..790ca96b 100644 --- a/OpenFlow/src/Config.ts +++ b/OpenFlow/src/Config.ts @@ -68,7 +68,7 @@ export class dbConfig extends Base { if(["license_key", "otel_trace_url", "cache_store_type", "cache_store_redis_host", "cache_store_max", "grafana_url", "workitem_queue_monitoring_interval", "NODE_ENV", "validate_emails", "amqp_url", "port", "saml_issuer", "saml_federation_metadata", "api_ws_url", "domain", "enable_openapi", "enable_openapiauth", "ping_clients_interval", "tls_crt", "tls_key", "tls_ca", - "otel_metric_url", "otel_trace_url", "multi_tenant" ].indexOf(key) > -1 ) { + "otel_metric_url", "otel_trace_url", "multi_tenant", "auto_hourly_housekeeping" ].indexOf(key) > -1 ) { if(os.hostname().toLowerCase() == "nixos") { continue; } @@ -118,7 +118,7 @@ export class dbConfig extends Base { if(["license_key", "otel_trace_url", "cache_store_type", "cache_store_redis_host", "cache_store_max", "grafana_url", "workitem_queue_monitoring_interval", "NODE_ENV", "validate_emails", "amqp_url", "port", "saml_issuer", "saml_federation_metadata", "api_ws_url", "domain", "enable_openapi", "enable_openapiauth", "ping_clients_interval", "tls_crt", "tls_key", "tls_ca", - "otel_metric_url", "otel_trace_url", "multi_tenant" ].indexOf(key) > -1 ) { + "otel_metric_url", "otel_trace_url", "multi_tenant", "auto_hourly_housekeeping" ].indexOf(key) > -1 ) { if(os.hostname().toLowerCase() == "nixos") { continue; } diff --git a/OpenFlow/src/DatabaseConnection.ts b/OpenFlow/src/DatabaseConnection.ts index 3acb0666..46375480 100644 --- a/OpenFlow/src/DatabaseConnection.ts +++ b/OpenFlow/src/DatabaseConnection.ts @@ -4580,6 +4580,41 @@ export class DatabaseConnection extends events.EventEmitter { public static timeseries_collections: string[] = []; public static timeseries_collections_metadata: any = {}; public static timeseries_collections_time: any = {}; + public async UpdateIndexTypes(parent: Span) { + try { + let collections = await DatabaseConnection.toArray(this.db.listCollections()); + collections = collections.filter(x => x.name.indexOf("system.") === -1); + + DatabaseConnection.timeseries_collections = []; + for (let i = 0; i < collections.length; i++) { + var collection = collections[i]; + if (collection.type == "timeseries") { + DatabaseConnection.timeseries_collections = DatabaseConnection.timeseries_collections.filter(x => x != collection.name); + DatabaseConnection.timeseries_collections.push(collection.name); + } + } + DatabaseConnection.timeseries_collections = []; + DatabaseConnection.collections_with_text_index = []; + for (let i = 0; i < collections.length; i++) { + var collection = collections[i]; + if (collection.type == "timeseries") { + DatabaseConnection.timeseries_collections = DatabaseConnection.timeseries_collections.filter(x => x != collection.name); + DatabaseConnection.timeseries_collections.push(collection.name); + } + if (collection.type != "collection" && collection.type != "timeseries") continue; + parent?.addEvent("Get indexes for " + collection.name); + const indexes = await this.db.collection(collection.name).indexes(); + for (let y = 0; y < indexes.length; y++) { + var idx = indexes[y]; + if (idx.textIndexVersion && idx.textIndexVersion > 1 && collection.name != "fs.files") { + DatabaseConnection.collections_with_text_index = DatabaseConnection.collections_with_text_index.filter(x => x != collection.name); + DatabaseConnection.collections_with_text_index.push(collection.name); + } + } + } + } catch (error) { + } + } async ensureindexes(parent: Span) { const span: Span = Logger.otel.startSubSpan("db.ensureindexes", parent); try { @@ -4597,25 +4632,7 @@ export class DatabaseConnection extends events.EventEmitter { } } if (!Config.ensure_indexes) { - DatabaseConnection.timeseries_collections = []; - DatabaseConnection.collections_with_text_index = []; - for (let i = 0; i < collections.length; i++) { - var collection = collections[i]; - if (collection.type == "timeseries") { - DatabaseConnection.timeseries_collections = DatabaseConnection.timeseries_collections.filter(x => x != collection.name); - DatabaseConnection.timeseries_collections.push(collection.name); - } - if (collection.type != "collection" && collection.type != "timeseries") continue; - span?.addEvent("Get indexes for " + collection.name); - const indexes = await this.db.collection(collection.name).indexes(); - for (let y = 0; y < indexes.length; y++) { - var idx = indexes[y]; - if (idx.textIndexVersion && idx.textIndexVersion > 1 && collection.name != "fs.files") { - DatabaseConnection.collections_with_text_index = DatabaseConnection.collections_with_text_index.filter(x => x != collection.name); - DatabaseConnection.collections_with_text_index.push(collection.name); - } - } - } + await this.UpdateIndexTypes(span); return; } diff --git a/OpenFlow/src/Messages/Message.ts b/OpenFlow/src/Messages/Message.ts index 7f4edc3c..96f62f2b 100644 --- a/OpenFlow/src/Messages/Message.ts +++ b/OpenFlow/src/Messages/Message.ts @@ -3610,6 +3610,7 @@ export class Message { Logger.otel.endSpan(span); } } + public async _Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise { if (Message.lastHouseKeeping == null) { Message.lastHouseKeeping = new Date(); diff --git a/OpenFlow/src/index.ts b/OpenFlow/src/index.ts index 903cbd11..6a4640aa 100644 --- a/OpenFlow/src/index.ts +++ b/OpenFlow/src/index.ts @@ -90,6 +90,10 @@ async function initDatabase(parent: Span): Promise { cerror(error); process.exit(404); } + try { + await Config.db.UpdateIndexTypes(span); + } catch (error) { + } diff --git a/OpenFlow/src/public/CommonControllers.ts b/OpenFlow/src/public/CommonControllers.ts index 2c8b45b3..73c03d65 100644 --- a/OpenFlow/src/public/CommonControllers.ts +++ b/OpenFlow/src/public/CommonControllers.ts @@ -727,13 +727,16 @@ export class entitiesCtrl { } } - if (this.WebSocketClientService.collections_with_text_index.indexOf(this.collection) == -1) { + if (this.WebSocketClientService.timeseries_collections.indexOf(this.collection) == -1 && + this.WebSocketClientService.collections_with_text_index.indexOf(this.collection) == -1) { if (NoderedUtil.IsNullUndefinded(this.orderby) || Object.keys(this.orderby).length == 0) { orderby = { _created: -1 }; } } else { if (NoderedUtil.IsNullUndefinded(this.orderby) || Object.keys(this.orderby).length == 0) { - orderby = { _created: -1 }; + if(this.collection == "audit" || this.collection == "dbusage") { + orderby = { _created: -1 }; + } } if (!NoderedUtil.IsNullEmpty(this.searchstring) && !this.searchstring.startsWith(".")) { // Remove order by when using text index @@ -741,7 +744,6 @@ export class entitiesCtrl { } } if (this.page == 0) { - this.models = await NoderedUtil.Query({ collectionname: this.collection, query, projection: this.baseprojection, orderby, top: this.pagesize, queryas: basequeryas }); } else { var temp = await NoderedUtil.Query({ collectionname: this.collection, query, projection: this.baseprojection, orderby, top: this.pagesize, skip: this.pagesize * this.page, queryas: basequeryas }); diff --git a/OpenFlow/src/public/Controllers.ts b/OpenFlow/src/public/Controllers.ts index 54ce4136..ea9b2dac 100644 --- a/OpenFlow/src/public/Controllers.ts +++ b/OpenFlow/src/public/Controllers.ts @@ -3034,6 +3034,7 @@ export class EntitiesCtrl extends entitiesCtrl { if (!this.$scope.$$phase) { this.$scope.$apply(); } } SelectCollection() { + if (!this.userdata.data.EntitiesCtrl) this.userdata.data.EntitiesCtrl = {}; this.userdata.data.EntitiesCtrl.collection = this.collection; this.$location.path("/Entities/" + this.collection); //this.$location.hash("#/Entities/" + this.collection); @@ -8332,6 +8333,7 @@ export class AgentCtrl extends entityCtrl { this.basequery = { _id: this.id }; await NoderedUtil.CustomCommand({ command: "startagent", id: this.model._id, name: this.model.slug }) } + this.$location.path("/Agent/" + this.id); } this.loading = false; if (this.model) { this.loadData(); } diff --git a/package.json b/package.json index b7f13f06..6833151a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openiap/openflow", - "version": "1.5.3", + "version": "1.5.4", "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)", "main": "index.js", "scripts": {