Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions ddss/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ async def main(session: async_sessionmaker[AsyncSession]) -> None:
for i in await sess.scalars(select(Facts).where(Facts.id > max_fact)):
max_fact = max(max_fact, i.id)
chain.add(i.data)
tasks = []

def handler(rule):
for rule in chain:
ds = str(rule)
if idea := str_rule_get_str_idea(ds):
tasks.append(asyncio.create_task(insert_or_ignore(sess, Ideas, idea)))
await insert_or_ignore(sess, Ideas, idea)
else:
tasks.append(asyncio.create_task(insert_or_ignore(sess, Facts, ds)))
return False
await insert_or_ignore(sess, Facts, ds)

chain.execute(handler)
await asyncio.gather(*tasks)
await sess.commit()

await asyncio.sleep(0)
Expand Down
14 changes: 4 additions & 10 deletions ddss/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ export async function main(sequelize: Sequelize): Promise<void> {
chain.add(fact.data);
}

const tasks: Promise<void>[] = [];

const handler = (rule: Rule) => {
for (const rule of chain) {
const ds = rule.toString();
const idea = strRuleGetStrIdea(ds);
if (idea) {
tasks.push(insertOrIgnore(Idea, idea));
await insertOrIgnore(Idea, idea);
Comment on lines +21 to +25
} else {
tasks.push(insertOrIgnore(Fact, ds));
await insertOrIgnore(Fact, ds);
}
Comment on lines +21 to 28
return false;
};

chain.execute(handler);
await Promise.all(tasks);
}

await new Promise((resolve) => setTimeout(resolve, 0));
}
Expand Down
10 changes: 3 additions & 7 deletions ddss/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ async def main(session: async_sessionmaker[AsyncSession]) -> None:
for i in await sess.scalars(select(Facts).where(Facts.id > max_fact)):
max_fact = max(max_fact, i.id)
search.add(i.data)
tasks = []

def handler(rule):
for rule in search:
ds = str(rule)
tasks.append(asyncio.create_task(insert_or_ignore(sess, Facts, ds)))
await insert_or_ignore(sess, Facts, ds)
if idea := str_rule_get_str_idea(ds):
tasks.append(asyncio.create_task(insert_or_ignore(sess, Ideas, idea)))
return False
await insert_or_ignore(sess, Ideas, idea)

search.execute(handler)
await asyncio.gather(*tasks)
await sess.commit()

await asyncio.sleep(0)
Expand Down
14 changes: 4 additions & 10 deletions ddss/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ export async function main(sequelize: Sequelize): Promise<void> {
search.add(fact.data);
}

const tasks: Promise<void>[] = [];

const handler = (rule: Rule) => {
for (const rule of search) {
const ds = rule.toString();
tasks.push(insertOrIgnore(Fact, ds));
await insertOrIgnore(Fact, ds);
Comment on lines +21 to +23
const idea = strRuleGetStrIdea(ds);
if (idea) {
tasks.push(insertOrIgnore(Idea, idea));
await insertOrIgnore(Idea, idea);
}
Comment on lines +21 to 27
return false;
};

search.execute(handler);
await Promise.all(tasks);
}

await new Promise((resolve) => setTimeout(resolve, 0));
}
Expand Down
Loading