我正在使用带有> 的生产者/消费者模式System.Collection.Concurrent.BlockingCollection<DataTable来从数据库(生产者)检索数据并在数据(消费者)上创建Lucene索引.
Producer一次抓取10000条记录并将该组添加到BlockingCollection<DataTable>.然后消费者(稍微慢一点)抓住那些10000并创建一个索引.
阻塞集合被限制为<DataTable>每个10000行中的5个.
起初程序运行得很好,但是在它获得大约150000行后,我注意到我的计算机内存最大化并且它慢慢爬行.
似乎BlockingCollection无法null在获取项目后将基础数组槽设置为.
码:
private static LuceneIndex index;
private static BlockingCollection<DataTable> blockingCol;
private static void Producer()
{
while (true)
{
//...get next 10000 rows
DataTable data = GetNextSet();
if(data.Row.Count > 0)
blockingCol.Add(products);
else
break;
}
}
private static void Consumer()
{
while (!BlockingCol.IsCompleted || BlockingCol.Count > 0)
{
DataTable data = blockingCol.Take();
index.UpdateIndex(GetLuceneDocs(data));
}
}
public static void Main(System.String[] args)
{
index = new LuceneIndex();
blockingCol …Run Code Online (Sandbox Code Playgroud) 我有一个antd 表,我想在其中汇总页脚中的列。但是,我在让它们与我的专栏正确对齐时遇到了问题。我尝试使用Row/Col来匹配它,但运气不佳。它还需要响应...
<Table
columns={columns}
dataSource={tableData}
footer={
<Row>
<Col span={8}>
<strong>TOTALS:</strong>
</Col>
<Col span={2}>
123
</Col>
<Col span={3} />
<Col span={2}>
123
</Col>
<Col span={2} />
<Col span={2}>
123
</Col >
<Col span={8} />
</Row>
}
/>
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现这一目标?
我正在使用轻量级 ORM 将我的 React 应用程序与外部服务连接...此包返回模型的对象并允许您直接对它们执行操作。虽然这真的很棒,但我很难弄清楚如何将这些对象包含在其中state并仍然遵循“从不直接修改状态”的反应租户。
如果我有一个更新帐户名的组件,这样做可以接受吗?
interface IAppState {
account: Account
}
class App extends React.Component<{}, IAppState> {
constructor(props) {
super(props);
this.state = {
account: new Account()
}
}
//set the new name and update the external service
public updateAccount = (newName: string)=>{
account.name = newName; //REDFLAG!!!
acc.update().then(()=>{
this.setState({ account: this.state.account })
})
}
//retrieve our account object from external service
public componentDidMount() {
const qParams = queryString.parse(window.location.search);
Account.get(qParams.externalId).then((acc)=>{
this.setState({account: acc})
})
}
render() {
return <NameEditor handleClick={this.updateAccount} …Run Code Online (Sandbox Code Playgroud) 所以也许我很困惑,但是我想如果我将declaration:truetsconfig.json 添加到tsconfig.json中,我可以让tsc复制我的*.d.ts文件,以及已转码的代码及其d.ts文件?
例如:
- src
- lib
- types.d.ts
- foo.ts
Run Code Online (Sandbox Code Playgroud)
我希望tsc的结果像这样:
- build
- lib
- types.d.ts
- foo.js
- foo.d.ts
Run Code Online (Sandbox Code Playgroud)
但是,我似乎types.d.ts无法复制到构建目录中。
打字稿是否不提供任何复制.d.ts文件的机制?还是我只是某个地方配置错误?(目前我已经尝试了许多不同的配置;似乎没有任何效果)
假设我有一个 RESTish API 来管理“帖子”。
GET /posts返回所有帖子PATCH /posts:id更新帖子并回复新记录数据我可以通过如下方式使用 RTK 查询来实现此目的:
const TAG_TYPE = 'POST';
// Define a service using a base URL and expected endpoints
export const postsApi = createApi({
reducerPath: 'postsApi',
tagTypes: [TAG_TYPE],
baseQuery,
endpoints: (builder) => ({
getPosts: builder.query<Form[], string>({
query: () => `/posts`,
providesTags: (result) =>
[
{ type: TAG_TYPE, id: 'LIST' },
],
}),
updatePost: builder.mutation<any, { formId: string; formData: any }>({
// note: an optional `queryFn` may be used in place of …Run Code Online (Sandbox Code Playgroud) Redux最佳做法建议您标准化状态形状
基本上,这意味着:
const blogPosts = [
{
id : "post1",
author : {username : "user1", name : "User 1"},
body : "......",
comments : [
{
id : "comment1",
author : {username : "user2", name : "User 2"},
comment : ".....",
},
{
id : "comment2",
author : {username : "user3", name : "User 3"},
comment : ".....",
}
]
},
{
id : "post2",
author : {username : "user2", name : "User 2"},
body : "......",
comments : …Run Code Online (Sandbox Code Playgroud) 我有一个正在通过的减速器测试,但最后抛出了这个奇怪的错误:
console.error node_modules/redux/lib/utils/warning.js:14
No reducer provided for key "newProducts"
Run Code Online (Sandbox Code Playgroud)
src/reducer/index.ts
import newLineItemReducer from "./newLineItemReducer";
import renewedLineItemReducer from "./renewedLineItemReducer";
export interface LineItemState{
renewedProducts: LineItem[]
newProducts: LineItem[]
}
//used by both reducers
export interface LineItem{
...
}
// used by both "new" and "renewed" slice reducers
export function sharedFunction1() {
...
}
export default combineReducers<LineItemState>({
renewedProducts: renewedLineItemReducer,
newProducts: newLineItemReducer
});
Run Code Online (Sandbox Code Playgroud)
src/reducer/newLineItemReducer.ts
import {LineItem, sharedFunction1 } from "./";
type Action = ...;
const newLineItemReducer =
(state: LineItem[] = [], action: Action): LineItem[] => …Run Code Online (Sandbox Code Playgroud) 我想做一些类似于本文档中概述的选择进程的操作,但我只想能够输入任何字符串:
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}",
"port": 9229
}
Run Code Online (Sandbox Code Playgroud)
是否有可以用来获取任何用户输入的命令?理想情况下,我可以做这样的事情:
{
"name": "Launch Chrome Debug",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080/?id=${command:UserInput}",
"webRoot": "${workspaceRoot}",
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以在启动调试器时指定“id”参数。
我正在开发一个项目,经常需要转换 ES6 映射中的每个值:
const positiveMap = new Map(
[
['hello', 1],
['world', 2]
]
);
const negativeMap = new Map<string, number>();
for (const key of positiveMap.keys()) {
negativeMap.set(key, positiveMap.get(key) * -1);
}
Run Code Online (Sandbox Code Playgroud)
只是想知道是否有更好的方法来做到这一点?理想情况下是像这样的单衬Array.map()。
如果它在打字稿中编译的话,奖励积分(不是真的)!
typescript ×5
reactjs ×2
redux ×2
.d.ts ×1
.net ×1
antd ×1
es6-map ×1
javascript ×1
jestjs ×1
memory-leaks ×1
rtk-query ×1
subsonic ×1
xmltable ×1