@@ -183,7 +183,10 @@ export class DatabaseConnection {
183183 const b = new Binary ( Buffer . from ( ace . rights , "base64" ) , 0 ) ;
184184 ( ace . rights as any ) = b ;
185185 }
186+ DatabaseConnection . mongodb_query_count . labels ( "users" ) . inc ( ) ;
187+ const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
186188 const arr = await this . db . collection ( "users" ) . find ( { _id : ace . _id } ) . project ( { name : 1 } ) . limit ( 1 ) . toArray ( ) ;
189+ end ( { collection : "users" } ) ;
187190 if ( arr . length == 0 ) {
188191 item . _acl . splice ( i , 1 ) ;
189192 } else { ace . name = arr [ 0 ] . name ; }
@@ -244,7 +247,10 @@ export class DatabaseConnection {
244247 if ( exists . length > 1 ) {
245248 item . members . splice ( i , 1 ) ;
246249 } else {
250+ DatabaseConnection . mongodb_query_count . labels ( "users" ) . inc ( ) ;
251+ const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
247252 const arr = await this . db . collection ( "users" ) . find ( { _id : ace . _id } ) . project ( { name : 1 , _acl : 1 , _type : 1 } ) . limit ( 1 ) . toArray ( ) ;
253+ end ( { collection : "users" } ) ;
248254 if ( arr . length == 0 ) {
249255 item . members . splice ( i , 1 ) ;
250256 }
@@ -262,7 +268,6 @@ export class DatabaseConnection {
262268 const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
263269 await this . db . collection ( "users" ) . updateOne ( { _id : u . _id } , { $set : { _acl : u . _acl } } ) ;
264270 end ( { collection : "users" } ) ;
265- // await this.db.collection("users").save(u);
266271 } else if ( u . _id != item . _id ) {
267272 this . _logger . debug ( item . name + " allready exists on " + u . name ) ;
268273 }
@@ -279,7 +284,6 @@ export class DatabaseConnection {
279284 const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
280285 await this . db . collection ( "users" ) . updateOne ( { _id : r . _id } , { $set : { _acl : r . _acl } } ) ;
281286 end ( { collection : "users" } ) ;
282- // await this.db.collection("users").save(r);
283287 } else if ( r . _id != item . _id ) {
284288 this . _logger . debug ( item . name + " allready exists on " + r . name ) ;
285289 }
@@ -294,7 +298,10 @@ export class DatabaseConnection {
294298 if ( Config . update_acl_based_on_groups ) {
295299 for ( let i = removed . length - 1 ; i >= 0 ; i -- ) {
296300 const ace = removed [ i ] ;
301+ DatabaseConnection . mongodb_query_count . labels ( "users" ) . inc ( ) ;
302+ const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
297303 const arr = await this . db . collection ( "users" ) . find ( { _id : ace . _id } ) . project ( { name : 1 , _acl : 1 , _type : 1 } ) . limit ( 1 ) . toArray ( ) ;
304+ end ( { collection : "users" } ) ;
298305 if ( arr . length == 1 && item . _id != WellknownIds . admins && item . _id != WellknownIds . root ) {
299306 if ( Config . multi_tenant && multi_tenant_skip . indexOf ( item . _id ) > - 1 ) {
300307 // when multi tenant don't allow members of common user groups to see each other
@@ -308,7 +315,6 @@ export class DatabaseConnection {
308315 const right = Base . getRight ( u , item . _id , false ) ;
309316 if ( right == null ) {
310317 this . _logger . debug ( "Removing " + item . name + " read permissions from " + u . name ) ;
311- // await this.db.collection("users").save(u);
312318 DatabaseConnection . mongodb_update_count . labels ( 'users' ) . inc ( ) ;
313319 const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
314320 await this . db . collection ( "users" ) . updateOne ( { _id : u . _id } , { $set : { _acl : u . _acl } } ) ;
@@ -327,7 +333,6 @@ export class DatabaseConnection {
327333 const right = Base . getRight ( r , item . _id , false ) ;
328334 if ( right == null ) {
329335 this . _logger . debug ( "Removing " + item . name + " read permissions from " + r . name ) ;
330- // await this.db.collection("users").save(r);
331336 DatabaseConnection . mongodb_update_count . labels ( 'users' ) . inc ( ) ;
332337 const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
333338 await this . db . collection ( "users" ) . updateOne ( { _id : r . _id } , { $set : { _acl : r . _acl } } ) ;
@@ -443,12 +448,6 @@ export class DatabaseConnection {
443448 }
444449 projection = null ;
445450 } else {
446- // if (!collectionname.endsWith("_hist")) {
447- // _query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
448- // } else {
449- // // todo: enforcer permissions when fetching _hist ?
450- // _query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
451- // }
452451 if ( ! NoderedUtil . IsNullEmpty ( queryas ) ) {
453452 _query = { $and : [ query , this . getbasequery ( jwt , "_acl" , [ Rights . read ] ) , await this . getbasequeryuserid ( queryas , "_acl" , [ Rights . read ] ) ] } ;
454453 } else {
@@ -457,11 +456,6 @@ export class DatabaseConnection {
457456 }
458457 if ( ! top ) { top = 500 ; }
459458 if ( ! skip ) { skip = 0 ; }
460- // if (collectionname == "openrpa") {
461- // const user: TokenUser = Crypt.verityToken(jwt);
462- // arr = await this.db.collection(collectionname).find(query).limit(top).skip(skip).toArray();
463- // _query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
464- // }
465459 let arr : T [ ] = [ ] ;
466460
467461
@@ -477,11 +471,6 @@ export class DatabaseConnection {
477471 }
478472 arr = await _pipe . toArray ( ) ;
479473 end ( { collection : collectionname } ) ;
480- // if (projection != null) {
481- // arr = await this.db.collection(collectionname).find(_query).project(projection).sort(mysort as any).limit(top).skip(skip).toArray();
482- // } else {
483- // arr = await this.db.collection(collectionname).find(_query).sort(mysort as any).limit(top).skip(skip).toArray();
484- // }
485474 for ( let i : number = 0 ; i < arr . length ; i ++ ) { arr [ i ] = this . decryptentity ( arr [ i ] ) ; }
486475 DatabaseConnection . traversejsondecode ( arr ) ;
487476 if ( Config . log_queries ) this . _logger . debug ( "[" + user . username + "][" + collectionname + "] query gave " + arr . length + " results " ) ;
@@ -582,7 +571,6 @@ export class DatabaseConnection {
582571 } else {
583572 aggregates = [ { $match : base } , aggregates ] ;
584573 }
585- // const items: T[] = await this.db.collection(collectionname).aggregate(aggregates).toArray();
586574 const options : CollectionAggregationOptions = { } ;
587575 options . hint = myhint ;
588576 try {
@@ -708,9 +696,6 @@ export class DatabaseConnection {
708696 if ( out . hasOwnProperty ( "inline" ) ) { inline = true ; }
709697 }
710698 opt . scope = scope ;
711- // opt.readPreference = ReadPreference.PRIMARY_PREFERRED;
712-
713- // const result:T[] = await this.db.collection(collectionname).mapReduce(map, reduce, {query: q, out : {inline : 1}});
714699 try {
715700 if ( inline ) {
716701 opt . out = { inline : 1 } ;
@@ -1275,7 +1260,10 @@ export class DatabaseConnection {
12751260 if ( collectionname === "files" ) { collectionname = "fs.files" ; }
12761261 if ( collectionname === "fs.files" ) {
12771262 _query = { $and : [ { _id : safeObjectID ( id ) } , this . getbasequery ( jwt , "metadata._acl" , [ Rights . delete ] ) ] } ;
1263+ DatabaseConnection . mongodb_query_count . labels ( collectionname ) . inc ( ) ;
1264+ const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
12781265 const arr = await this . db . collection ( collectionname ) . find ( _query ) . toArray ( ) ;
1266+ end ( { collection : collectionname } ) ;
12791267 if ( arr . length == 1 ) {
12801268 DatabaseConnection . mongodb_delete_count . labels ( collectionname ) . inc ( ) ;
12811269 const end = DatabaseConnection . mongodb_delete . startTimer ( ) ;
@@ -1340,10 +1328,16 @@ export class DatabaseConnection {
13401328
13411329 if ( collectionname === "files" ) { collectionname = "fs.files" ; }
13421330 if ( collectionname === "fs.files" ) {
1331+ DatabaseConnection . mongodb_query_count . labels ( collectionname ) . inc ( ) ;
1332+ const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
13431333 const arr = await this . db . collection ( collectionname ) . find ( _query ) . toArray ( ) ;
1334+ end ( { collection : collectionname } ) ;
13441335 this . _logger . debug ( "[" + user . username + "][" + collectionname + "] Deleting " + arr . length + " files in database" ) ;
13451336 for ( let i = 0 ; i < arr . length ; i ++ ) {
1337+ DatabaseConnection . mongodb_deletemany_count . labels ( collectionname ) . inc ( ) ;
1338+ const end = DatabaseConnection . mongodb_deletemany . startTimer ( ) ;
13461339 await this . _DeleteFile ( arr [ i ] . _id ) ;
1340+ end ( { collection : collectionname } ) ;
13471341 }
13481342 // if (Config.log_deletes) console.log(JSON.parse(JSON.stringify(query)));
13491343 if ( Config . log_deletes ) this . _logger . verbose ( "[" + user . username + "][" + collectionname + "] deleted " + arr . length + " items in database" ) ;
0 commit comments