我有一个products
带有整数字段的索引size
。我想删除大小为 10 的所有文档。我有超过 5000 个大小为 10 的文档。如果我尝试:
DELETE /products/product/_query?q=size:10
Run Code Online (Sandbox Code Playgroud)
此查询需要超过 2 分钟。
我delete by query
从文档中了解到,因为插件很慢:
在内部,它使用 Scroll 和 Bulk API 以高效且安全的方式删除文档。它更慢[..] 匹配大量文档的查询可能会运行很长时间,因为每个文档都必须单独删除。
如何执行最快的文档批量删除?
BaseComponent
我有一个带有方法的基类,我希望所有扩展我的方法并重写该方法的foo()
类始终调用超级方法:BaseComponent
foo()
export class BaseComponent {
foo(){}
}
export class ExtendedComponent extends BaseComponent {
constructor(){
super();
}
// BAD
foo(){
}
// GOOD
foo(){
super.foo();
}
}
Run Code Online (Sandbox Code Playgroud)
Typescript 中的一些技巧?
我有一个肥皂方法,即时创建和回复PDF内容.
在方法上finally
,临时pdf文件被删除.
这是finally
执行此操作的正确位置?
procedure TWbModule.WbModuleGetPDFAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
aPDFFileTemp : string;
begin
try
// getTempPdf() creates and returns the PDF path, eg.: C:\files\foo.pdf
aPDFFileTemp := getTempPdf();
// set response content stream with file stream
Response.ContentStream := TFileStream.Create(aPDFFileTemp, fmOpenRead or fmShareDenyNone);
Response.ContentType := 'application/pdf';
finally
// delete temporary file
// It is the right place for perform this operation?
if FileExists(aPDFFileTemp) then DeleteFile(aPDFFileTemp );
end;
end;
Run Code Online (Sandbox Code Playgroud) 我有一个大的txt(ipaddress.txt),有很多行,每行是一个IP地址,例如:
44.XXX.XXX.XXX
45.XXX.XXX.XXX
46.XXX.XXX.XXX
47.XXX.XXX.XXX
48.XXX.XXX.XXX
Run Code Online (Sandbox Code Playgroud)
我加载此列表TStringList
,例如:
FIpAddressList := TStringList.Create();
FIpAddressList.Sorted := true;
FIpAddressList.LoadFromFile('ipaddress.txt');
Run Code Online (Sandbox Code Playgroud)
我想检查列表中是否有IP地址,例如:
function IsIPinList(const IPAddress : string): Boolean;
begin
Result := (FIpAddressList.IndexOf(IPAddress) <> -1);
end;
Run Code Online (Sandbox Code Playgroud)
它有效......但是速度很慢TStringList
.
有没有办法让这个过程更快?
UPDATE
create-react-app
通过设置代理,有任何方法可以在公司防火墙后面工作.
我已经在npm和yarn上设置了代理,但这是我在尝试时看到的create-react-app my-app
:
Creating a new React app in F:\react\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
You appear to be offline.
Falling back to the local Yarn cache.
yarn add v0.23.4
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find any versions for "react" that matches "latest" in our cache. Possible versions: ""
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Aborting installation.
yarnpkg add --exact --offline react …
Run Code Online (Sandbox Code Playgroud) tsling引发错误:
第1行:模块内部不需要'use strict'(严格)
这是我的代码
"use strict";
function Foo() {}
Foo.prototype.sayHello= function () {
console.log("hello!");
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = {
Foo: Foo
};
}
Run Code Online (Sandbox Code Playgroud)
怎么修复这个错误?
边注
我的代码同时使用module
和vanilla javascript.我只想"strict mode"
用于香草javascript.
也许我可以使用
if (typeof module !== 'undefined') {
"use strict";
}
Run Code Online (Sandbox Code Playgroud)
strict mode
仅启用vanilla javascript?
我有一个返回 Observable 的方法
subFoo(id): Observable<number> {
return new Observable<number>(observer => {
setTimeout(() => {
observer.next(id);
}, 1000);
});
}
Run Code Online (Sandbox Code Playgroud)
现在我订阅了三次,5秒后全部取消订阅:
const sub1 = subFoo(1).subscribe(result => console.log(result));
const sub2 = subFoo(2).subscribe(result => console.log(result));
const sub3 = subFoo(3).subscribe(result => console.log(result));
setTimeout(() => {
sub1.unsubscribe();
sub2.unsubscribe();
sub3.unsubscribe();
}, 5000);
Run Code Online (Sandbox Code Playgroud)
我可以处理所有听众的完全取消订阅吗?
例如。(伪代码):
subFoo(id): Observable<number> {
return new Observable<number>(observer => {
// something like this
observer.onAllListenerAreUnsubscribed(() => {
console.log('All Listener Are Unsubscribed!');
});
setTimeout(() => {
observer.next(id);
}, 1000);
});
}
Run Code Online (Sandbox Code Playgroud)
我想在组件中使用芯片
my-comp.module.html
<mat-form-field class="example-chip-list" #chipList>
<mat-chip-list>
<mat-chip *ngFor="let role of user.roles" [selectable]="selectable"
[removable]="removable"
(removed)="remove(role)">{{ role.name }}</mat-chip>
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
<input
placeholder="New fruit..."
#fruitInput
[formControl]="fruitCtrl"
[matAutocomplete]="auto"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)">
</mat-chip-list>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
my-comp.module.ts
@NgModule({
declarations: [MyComp],
imports: [
CommonModule,
MatButtonModule,
MatIconModule,
FlexLayoutModule,
FormsModule,
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
MatChipsModule,
MatAutocompleteModule
],
exports: [MyComp]
})
export class MyCompModule { }
Run Code Online (Sandbox Code Playgroud)
但这会引发错误:
error-handler.service.ts:11 Error: StaticInjectorError(AppModule)[MatChipRemove -> MatChip]:
StaticInjectorError(Platform: core)[MatChipRemove -> MatChip]:
NullInjectorError: No provider for MatChip!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:717)
at resolveToken (core.js:954)
at tryResolveToken (core.js:898) …
Run Code Online (Sandbox Code Playgroud) 使用pdf.js,我做了一个简单的函数来从 pdf 中提取原始文本:
async getPdfText(path){
const pdf = await PDFJS.getDocument(path);
const pagePromises = [];
for (let j = 1; j <= pdf.numPages; j++) {
const page = pdf.getPage(j);
pagePromises.push(page.then((page) => {
const textContent = page.getTextContent();
return textContent.then((text) => {
return text.items.map((s) => s.str).join('');
});
}));
}
const texts = await Promise.all(pagePromises);
return texts.join('');
}
// usage
getPdfText("C:\\my.pdf").then((text) => { console.log(text); });
Run Code Online (Sandbox Code Playgroud)
但是我找不到正确提取新行的方法,所有文本仅在一行中提取。
如何正确提取文本?我想以与台式电脑相同的方式提取文本:
打开pdf(双击文件)-> 选择所有文本(CTRL + A)-> 复制所选文本(CTRL + C)-> 粘贴复制的文本(CTRL + V)
我想通过指令禁用一些按钮(向按钮添加禁用属性)。
该指令适用于经典的 html 按钮,但不适用于有角度的材料设计按钮(mat-button):
import { Component, Directive, ElementRef, Renderer2 } from '@angular/core';
@Directive({
selector: '[myDisableButton]'
})
export class HideCantEditDirective {
constructor(private el: ElementRef, private renderer: Renderer2) {
// try with Renderer2
this.renderer.setProperty(this.el.nativeElement, 'disabled', true);
// try with ElementRef
this.el.nativeElement.disabled = true;
this.renderer.setStyle(this.el.nativeElement, 'border', '2px solid green');
}
}
@Component({
selector: 'my-app',
template: `
<button mat-button myDisableButton (click)="onClick()">Material Button</button><br /><br />
<button myDisableButton (click)="onClick()">Classic Button</button>`,
styles: [ 'button:disabled { border: 2px solid red !important; }' ]
})
export …
Run Code Online (Sandbox Code Playgroud) javascript ×4
angular ×2
delphi ×2
typescript ×2
node.js ×1
pdf ×1
pdfjs ×1
reactjs ×1
rxjs ×1
soap ×1