Imports User Follows

The import script will now import hub user follows.
This commit is contained in:
Refringe 2024-09-24 00:43:15 -04:00
parent 2cd8e9fa86
commit 6bc02ca210
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k

View File

@ -49,6 +49,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
// Begin to import the data into the permanent local database tables.
$this->importUsers();
$this->importUserFollows();
$this->importLicenses();
$this->importSptVersions();
$this->importMods();
@ -608,6 +609,37 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
];
}
protected function importUserFollows(): void
{
$followsGroupedByFollower = [];
DB::connection('mysql_hub')
->table('wcf1_user_follow')
->select(['followID', 'userID', 'followUserID', 'time'])
->chunkById(100, function (Collection $follows) use (&$followsGroupedByFollower) {
foreach ($follows as $follow) {
$followerId = User::whereHubId($follow->userID)->value('id');
$followingId = User::whereHubId($follow->followUserID)->value('id');
if (! $followerId || ! $followingId) {
continue;
}
$followsGroupedByFollower[$followerId][$followingId] = [
'created_at' => Carbon::parse($follow->time, 'UTC'),
'updated_at' => Carbon::parse($follow->time, 'UTC'),
];
}
}, 'followID');
foreach ($followsGroupedByFollower as $followerId => $followings) {
$user = User::find($followerId);
if ($user) {
$user->following()->sync($followings);
}
}
}
/**
* Import the licenses from the Hub database to the local database.
*/