Skip to content

Commit

Permalink
Merge pull request #287 from skadefro/master
Browse files Browse the repository at this point in the history
close 1.5.4
skadefro authored Nov 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents eb9058a + 00a188d commit 74b491c
Showing 7 changed files with 51 additions and 25 deletions.
4 changes: 2 additions & 2 deletions OpenFlow/src/Config.ts
Original file line number Diff line number Diff line change
@@ -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;
}
55 changes: 36 additions & 19 deletions OpenFlow/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
@@ -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;
}

1 change: 1 addition & 0 deletions OpenFlow/src/Messages/Message.ts
Original file line number Diff line number Diff line change
@@ -3610,6 +3610,7 @@ export class Message {
Logger.otel.endSpan(span);
}
}

public async _Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise<void> {
if (Message.lastHouseKeeping == null) {
Message.lastHouseKeeping = new Date();
4 changes: 4 additions & 0 deletions OpenFlow/src/index.ts
Original file line number Diff line number Diff line change
@@ -90,6 +90,10 @@ async function initDatabase(parent: Span): Promise<boolean> {
cerror(error);
process.exit(404);
}
try {
await Config.db.UpdateIndexTypes(span);
} catch (error) {
}



8 changes: 5 additions & 3 deletions OpenFlow/src/public/CommonControllers.ts
Original file line number Diff line number Diff line change
@@ -727,21 +727,23 @@ export class entitiesCtrl<T> {

}
}
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
orderby = null;
}
}
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 });
2 changes: 2 additions & 0 deletions OpenFlow/src/public/Controllers.ts
Original file line number Diff line number Diff line change
@@ -3034,6 +3034,7 @@ export class EntitiesCtrl extends entitiesCtrl<Base> {
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<any> {
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(); }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {

0 comments on commit 74b491c

Please sign in to comment.