-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Runner] Avatars can be seen in membership list & member detail (#2944)
* [Runner] Avatars can be seen in membership list & member detail Related [card](dust-tt/tasks#289) and [discussion](https://dust4ai.slack.com/archives/C050SM8NSPK/p1702990922381299?thread_ts=1702899295.554769&cid=C050SM8NSPK) * switch back to message context
- Loading branch information
1 parent
b720bd7
commit 3c3c276
Showing
4 changed files
with
104 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
AgentConfiguration, | ||
Membership, | ||
User, | ||
UserMessage, | ||
} from "@app/lib/models"; | ||
|
||
async function main() { | ||
console.log("Starting imageUrl backfill"); | ||
const workspaceIds = ( | ||
await AgentConfiguration.findAll({ | ||
attributes: ["workspaceId"], | ||
group: ["workspaceId"], | ||
}) | ||
).map((a) => a.workspaceId); | ||
|
||
console.log(`Found ${workspaceIds.length} workspaces to update`); | ||
const chunks = []; | ||
for (let i = 0; i < workspaceIds.length; i += 16) { | ||
chunks.push(workspaceIds.slice(i, i + 16)); | ||
} | ||
|
||
for (let i = 0; i < chunks.length; i++) { | ||
console.log(`Processing workspace chunk ${i}/${chunks.length}...`); | ||
const chunk = chunks[i]; | ||
|
||
await Promise.all( | ||
chunk.map((wid: number) => { | ||
return (async () => { | ||
await backfillImageUrl(wid); | ||
})(); | ||
}) | ||
); | ||
} | ||
} | ||
|
||
async function backfillImageUrl(workspaceId: number) { | ||
// get all users from workspace whose imageUrl is null | ||
const users = await User.findAll({ | ||
where: { | ||
imageUrl: null, | ||
}, | ||
include: [ | ||
{ | ||
model: Membership, | ||
where: { | ||
workspaceId, | ||
}, | ||
required: true, | ||
}, | ||
], | ||
}); | ||
|
||
// for each user, find the last usermessage | ||
// and set the user's imageUrl to the usermessage's userContextProfilePictureUrl | ||
for (const user of users) { | ||
const userMessage = await UserMessage.findOne({ | ||
where: { | ||
userId: user.id, | ||
}, | ||
order: [["createdAt", "DESC"]], | ||
}); | ||
if (!userMessage) { | ||
console.log( | ||
`No user messages found for user with id ${user.id} in workspace with id ${workspaceId}` | ||
); | ||
continue; | ||
} | ||
|
||
await user.update({ | ||
imageUrl: userMessage.userContextProfilePictureUrl, | ||
}); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log("Done"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |