小编Abh*_*kar的帖子

在 Nest.js 应用程序中使用工作线程的正确方法

我正在创建一个 Nest.js 应用程序,并希望考虑该应用程序的可扩展性。我发现基本上有两种扩展方法:集群或工作线程。我已经在这里询问了有关 Node.js 应用程序的可扩展性的问题Docker vs Cluster with Node.js。并发现最好用 docker 包装应用程序并从中创建克隆,而不是集群。所以,我已经使用 Nest.js 应用程序做到了这一点,但问题是:

  1. 我们如何在 Nest.js 中使用工作线程来处理 CPU 密集型任务?
  2. 我们应该只导入工作线程并使用它,还是 Nest.js 中有特殊的语法允许我们使用工作线程?

node.js nestjs

8
推荐指数
2
解决办法
2万
查看次数

在“更新”操作中使用聚合管道更新数组的元素

设想

对于以下文档,我想更新数组中status特定消息messages的:

[{
    "_id" : ObjectId("6079bab4f297df39a44609cb"),
    "title" : "Test messages of single user",
    "messages" : [ 
        {
            "_id" : ObjectId("6079bab4f297df39a44609cc"),
            "body" : "Test 1",
            "status" : 1
        }, 
        {
            "_id" : ObjectId("6079bab4f297df39a44609cd"),
            "body" : "Test 2",
            "status" : 1
        }, 
        {
            "_id" : ObjectId("6079bcf7c041b00ec4cebb9d"),
            "body" : "Hello I'm Sam",
            "status" : 1
        }
    ]
}]
Run Code Online (Sandbox Code Playgroud)
  1. 更新操作中没有聚合管道的查询会更新单个消息中的状态

在这里运行下面的查询

db.update(
  { 
    "_id": ObjectId("6079bab4f297df39a44609cb"), 
    "messages": { $elemMatch: { _id: ObjectId("6079bcf7c041b00ec4cebb9d") } }
  }, …
Run Code Online (Sandbox Code Playgroud)

arrays nested mongodb mongodb-query

5
推荐指数
1
解决办法
4599
查看次数

mat-accordion 递归调用角度分量时出现滞后

我在手风琴中递归地调用组件以显示树状结构。

该代码适用于短输入,但在嵌套数据的递归调用上滞后

它就像一棵 json 树。

//sample.component.html
<app-tree [input]="data"></app-tree>


//tree.component.html

    <mat-accordion>
        <mat-expansion-panel hideToggle="true" (click)="toggleTree($event, input)">
          <mat-expansion-panel-header>
            <mat-panel-title>
                <mat-icon>{{input.buttonName}}</mat-icon>
                {{input.key}}
            </mat-panel-title>
          </mat-expansion-panel-header>
          <ul class="main-obj">   // tried *ngIf here
             <div class="obj-list" *ngFor="let item of input.value; trackBy: trackChanges">
                <li>
                  {{item.key}}: {{item.value}}
                </li>
                <li style="list-style: none; margin-left: -40px;">
                    <app-tree [input]="item"></app-tree>
                </li>
            </div>
         </ul>
        </mat-expansion-panel>
    </mat-accordion>

//tree.component.ts

    import { Component, OnInit, Input, Output } from '@angular/core';
    import { EventEmitter } from 'events';

    @Component({
      selector: 'app-tree',
      templateUrl: './tree.component.html',
      styleUrls: ['./tree.component.css']
    })

    export class TreeComponent implements OnInit { …
Run Code Online (Sandbox Code Playgroud)

tree recursion components angular angular8

1
推荐指数
1
解决办法
1604
查看次数