Update migration and service

This commit is contained in:
Daniel Supernault 2023-06-12 04:56:18 -06:00
parent 7dd45c23b7
commit b64af89d40
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 19 additions and 2 deletions

View file

@ -25,7 +25,7 @@ class ImportService
}
$start = 1;
$key = self::CACHE_KEY . 'getIdRange:incr:byUserId:' . $userId . ':y-' . $year . ':m-' . $month . ':d-' . $day;
$incr = Cache::increment($key, random_int(3, 19));
$incr = Cache::increment($key, random_int(5, 19));
if($incr > 999) {
$daysInMonth = now()->parse($day . '-' . $month . '-' . $year)->daysInMonth;
@ -64,7 +64,7 @@ class ImportService
Cache::forget($key);
}
return intval(Cache::remember($key, 21600, function() use($profileId) {
return ImportPost::whereProfileId($profileId)->count();
return ImportPost::whereProfileId($profileId)->whereSkipMissingMedia(false)->count();
}));
}
@ -73,6 +73,7 @@ class ImportService
$key = self::CACHE_KEY . 'attemptsByProfileId:' . $profileId;
return intval(Cache::remember($key, 21600, function() use($profileId) {
return ImportPost::whereProfileId($profileId)
->whereSkipMissingMedia(false)
->get()
->groupBy(function($item) {
return $item->created_at->format('Y-m-d');
@ -86,4 +87,19 @@ class ImportService
$key = self::CACHE_KEY . 'attemptsByProfileId:' . $profileId;
return Cache::forget($key);
}
public static function getImportedFiles($profileId, $refresh = false)
{
$key = self::CACHE_KEY . 'importedPostsByProfileId:' . $profileId;
if($refresh) {
Cache::forget($key);
}
return Cache::remember($key, 21600, function() use($profileId) {
return ImportPost::whereProfileId($profileId)
->get()
->map(function($ip) {
return collect($ip->media)->map(function($m) { return $m['uri']; });
})->flatten();
});
}
}

View file

@ -29,6 +29,7 @@ return new class extends Migration
$table->bigInteger('status_id')->unsigned()->nullable()->unique()->index();
$table->timestamp('creation_date')->nullable();
$table->json('metadata')->nullable();
$table->boolean('skip_missing_media')->default(false)->index();
$table->unique(['user_id', 'post_hash']);
$table->unique(['user_id', 'creation_year', 'creation_month', 'creation_day', 'creation_id'], 'import_posts_uid_phash_unique');
$table->timestamps();