remove "oldest" goal type

YAGNI KISS
This commit is contained in:
Andre Staltz 2023-10-12 15:26:27 +03:00
parent d8a0f841fe
commit 4e855f4f59
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 9 additions and 14 deletions

View File

@ -6,8 +6,8 @@ const Obz = require('obz')
* @typedef {import('ppppp-db').RecPresent} RecPresent * @typedef {import('ppppp-db').RecPresent} RecPresent
* @typedef {import('ppppp-db').Tangle} Tangle * @typedef {import('ppppp-db').Tangle} Tangle
* @typedef {ReturnType<PPPPPDB['getTangle']>} DBTangle * @typedef {ReturnType<PPPPPDB['getTangle']>} DBTangle
* @typedef {'none'|'all'|`newest-${number}`|`oldest-${number}`|'record'|'set'} GoalDSL * @typedef {'none'|'all'|`newest-${number}`|'record'|'set'} GoalDSL
* @typedef {'none'|'all'|'newest'|'oldest'|'record'|'set'} GoalType * @typedef {'none'|'all'|'newest'|'record'|'set'} GoalType
* @typedef {[number, number]} Range * @typedef {[number, number]} Range
* @typedef {{ id: string, type: GoalType, count: number }} Goal * @typedef {{ id: string, type: GoalType, count: number }} Goal
*/ */
@ -85,13 +85,6 @@ class GoalImpl {
return return
} }
const matchO = goalDSL.match(/^oldest-(\d+)$/)
if (matchO) {
this.#type = 'oldest'
this.#count = Number(matchO[1])
return
}
throw new Error(`Unrecognized goal DSL: ${goalDSL}`) throw new Error(`Unrecognized goal DSL: ${goalDSL}`)
} }
@ -139,9 +132,6 @@ function initGoals(peer, config) {
case 'newest': case 'newest':
const start = Math.max(0, maxDepth - goal.count + 1) const start = Math.max(0, maxDepth - goal.count + 1)
return [start, maxDepth] return [start, maxDepth]
case 'oldest':
const end = Math.min(maxDepth, goal.count - 1)
return [0, end]
} }
} }

View File

@ -79,6 +79,11 @@ test('getRecordPurpose', async (t) => {
domain: 'post', domain: 'post',
data: { text: 'm2' }, data: { text: 'm2' },
}) })
const post3 = await p(alice.db.feed.publish)({
account: aliceID,
domain: 'post',
data: { text: 'm3' },
})
const feedID = alice.db.feed.getID(aliceID, 'post') const feedID = alice.db.feed.getID(aliceID, 'post')
@ -89,8 +94,8 @@ test('getRecordPurpose', async (t) => {
const purpose = alice.goals.getRecordPurpose(post2) const purpose = alice.goals.getRecordPurpose(post2)
assert.equal(purpose, 'goal', 'purpose is "goal"') assert.equal(purpose, 'goal', 'purpose is "goal"')
alice.goals.set(feedID, 'oldest-1') alice.goals.set(feedID, 'newest-1')
assert('set goal to oldest-1') assert('set goal to newest-1')
const purpose2 = alice.goals.getRecordPurpose(post2) const purpose2 = alice.goals.getRecordPurpose(post2)
assert.equal(purpose2, 'none', 'purpose2 is "none"') assert.equal(purpose2, 'none', 'purpose2 is "none"')