/** * Choose which usernames to query next * If there are no free usernames at the moment, increae the length of the possible usernames by 1 * * @return mixed */ private function selectUsernames() { $toCheck = TwitterUser::neverQueried(); if ($toCheck->count() == 0) { return TwitterUser::orderBy('last_checked', 'asc')->take(100)->get()->pluck('username'); } return TwitterUser::neverQueried()->take(100)->get()->pluck('username'); }
/** * Decides of any more usernames should be added to the database * Will add more if any more of the same length need to be added * Won't add more if above condition passes and there are some usernames still to check or some available usernames * * @return bool */ private function populateMoreUsernames() { $currentLength = TwitterUser::select(DB::raw('MAX(CHAR_LENGTH(username)) as Max'))->pluck('Max'); if (is_null($currentLength) || !TwitterUser::whereUsername(str_repeat('_', $currentLength))->exists()) { return true; } if (TwitterUser::neverQueried()->count() > 0 || TwitterUser::free()->count() > 0) { return false; } return true; }