Skip to content

Commit

Permalink
feat(teach): migrate successor query to orm
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 14, 2021
1 parent 4808598 commit dcfc11e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
17 changes: 0 additions & 17 deletions packages/plugin-teach/src/database/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ export default function apply(ctx: Context) {
})
})

ctx.on('dialogue/mongo', ({ predecessors, stateful, noRecursive }, conditionals) => {
if (noRecursive) {
conditionals.push({ predecessors: { $size: 0 } })
} else if (predecessors !== undefined) {
if (stateful) {
conditionals.push({
$or: [
{ predecessors: { $size: 0 } },
{ predecessors: { $in: predecessors.map(i => i.toString()) } },
],
})
} else if (predecessors.length) {
conditionals.push({ predecessors: { $in: predecessors.map(i => i.toString()) } })
}
}
})

ctx.on('dialogue/mongo', (test, conditionals) => {
const expr = {
$multiply: [
Expand Down
13 changes: 0 additions & 13 deletions packages/plugin-teach/src/database/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ export default function apply(ctx: Context) {
)`)
})

ctx.on('dialogue/mysql', ({ predecessors, stateful, noRecursive }, conditionals) => {
if (noRecursive) {
conditionals.push('!`predecessors`')
} else if (predecessors !== undefined) {
const segments = predecessors.map(id => `FIND_IN_SET(${id}, \`predecessors\`)`)
if (stateful) {
conditionals.push(`(${['!`predecessors`', ...segments].join('||')})`)
} else if (predecessors.length) {
conditionals.push(`(${segments.join('||')})`)
}
}
})

function getProduct(time: number) {
return `(\`startTime\`-${time})*(${time}-\`endTime\`)*(\`endTime\`-\`startTime\`)`
}
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-teach/src/plugins/successor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,22 @@ export default function apply(ctx: Context, config: Dialogue.Config) {
}
}, dialogue.successorTimeout || successorTimeout)
})

ctx.on('dialogue/test', ({ predecessors, stateful, noRecursive }, query) => {
if (noRecursive) {
query.predecessors = { $size: 0 }
} else if (predecessors !== undefined) {
const $el = predecessors.map(i => i.toString())
if (stateful) {
query.$and.push({
$or: [
{ predecessors: { $size: 0 } },
{ predecessors: { $el } },
],
})
} else if (predecessors.length) {
query.predecessors = { $el }
}
}
})
}

0 comments on commit dcfc11e

Please sign in to comment.