unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import { Job, Queue } from 'bullmq'
2import { Op } from 'sequelize'
3import _ from 'underscore'
4import { FederatedHost, User } from '../../models/index.js'
5import { completeEnvironment } from '../backendOptions.js'
6import { getRemoteActorIdProcessor } from '../queueProcessors/getRemoteActorIdProcessor.js'
7import { getAdminUser } from '../getAdminAndDeletedUser.js'
8
9let adminUserPromise = getAdminUser()
10
11async function updateAllUsers() {
12 console.log('lets a update all users that we caaaaaaaaan')
13 let adminUser = await adminUserPromise
14
15 const allRemoteUsers = await User.findAll({
16 order: [['updatedAt', 'ASC']],
17 include: [
18 {
19 model: FederatedHost,
20 where: {
21 blocked: false
22 }
23 }
24 ],
25 where: {
26 banned: false,
27 url: {
28 [Op.like]: '@%@%'
29 },
30 updatedAt: {
31 // there are some old users that havent been updated in ages and could be deleted. will need fix later
32 [Op.gt]: new Date().setFullYear(2001)
33 }
34 }
35 })
36
37 for await (const chunk of _.chunk(allRemoteUsers, 50)) {
38 console.log('chunk started')
39 console.log(chunk[0].url)
40 await processChunk(chunk)
41 console.log('chunk finished')
42 }
43 console.log('------FINISHED-----')
44}
45
46async function processChunk(users: any[]) {
47 const promises = users.map(async (actor: any) =>
48 getRemoteActorIdProcessor({
49 data: { actorUrl: actor.remoteId, userId: (await adminUserPromise)?.id, forceUpdate: true }
50 } as Job)
51 )
52 try {
53 await Promise.allSettled(promises)
54 } catch (error) {
55 console.log('error in one of the chonks')
56 }
57}
58
59updateAllUsers()