Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new sorting option to categories
add new zset for category topics fix sorting names
- Loading branch information
1 parent
db2f7c0
commit 2a9b0a3
Showing
15 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
|
||
const db = require('../../database'); | ||
|
||
module.exports = { | ||
name: 'New sorted set cid:<cid>:tids:create', | ||
timestamp: Date.UTC(2024, 2, 4), | ||
method: async function () { | ||
const { progress } = this; | ||
const batch = require('../../batch'); | ||
await batch.processSortedSet('topics:tid', async (tids) => { | ||
let topicData = await db.getObjectsFields( | ||
tids.map(tid => `topic:${tid}`), | ||
['tid', 'cid', 'timestamp'] | ||
); | ||
topicData = topicData.filter(Boolean); | ||
topicData.forEach((t) => { | ||
t.timestamp = t.timestamp || Date.now(); | ||
}); | ||
|
||
await db.sortedSetAddBulk( | ||
topicData.map(t => ([`cid:${t.cid}:tids:create`, t.timestamp, t.tid])) | ||
); | ||
|
||
progress.incr(tids.length); | ||
}, { | ||
progress: this.progress, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
|
||
const db = require('../../database'); | ||
const batch = require('../../batch'); | ||
|
||
module.exports = { | ||
name: 'Change category sort settings', | ||
timestamp: Date.UTC(2024, 2, 4), | ||
method: async function () { | ||
const { progress } = this; | ||
|
||
const currentSort = await db.getObjectField('config', 'categoryTopicSort'); | ||
if (currentSort === 'oldest_to_newest' || currentSort === 'newest_to_oldest') { | ||
await db.setObjectField('config', 'categoryTopicSort', 'recently_replied'); | ||
} | ||
|
||
await batch.processSortedSet('users:joindate', async (uids) => { | ||
progress.incr(uids.length); | ||
const usersSettings = await db.getObjects(uids.map(uid => `user:${uid}:settings`)); | ||
const bulkSet = []; | ||
usersSettings.forEach((userSetting, i) => { | ||
if (userSetting && ( | ||
userSetting.categoryTopicSort === 'newest_to_oldest' || | ||
userSetting.categoryTopicSort === 'oldest_to_newest')) { | ||
bulkSet.push([ | ||
`user:${uids[i]}:settings`, { categoryTopicSort: 'recently_replied' }, | ||
]); | ||
} | ||
}); | ||
await db.setObjectBulk(bulkSet); | ||
}, { | ||
batch: 500, | ||
progress: progress, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters