Skip to content

Commit

Permalink
Merge pull request #26 from cbus-sea-lions-2015/fix-usersfetcher-nil-…
Browse files Browse the repository at this point in the history
…libraryid

fix libraries not being made on seed
  • Loading branch information
mdmartinez committed Apr 22, 2015
2 parents 516e314 + 4191536 commit f41bfbc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create
response = BggApi.new.collection({ username: bgg_user })
if response.keys[0] != "error"
library = Library.find_or_create_by(bgg_username: bgg_user)
UsersFetcher.perform_async(bgg_user,library.id)
UsersFetcher.perform_async(bgg_user)
user.library_id = library.id
user.save
message = 1
Expand Down
2 changes: 1 addition & 1 deletion app/workers/libraries_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class LibrariesFetcher
include Sidekiq::Worker

def perform(game_ids, library_id = nil)
def perform(game_ids, library_id)
game_ids.each_slice(100) do |slice|
GamesFetcher.perform_async(slice, library_id)
end
Expand Down
9 changes: 4 additions & 5 deletions app/workers/users_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class UsersFetcher
include Sidekiq::Worker

def perform(bgg_username,library_id = nil)
library = Library.find_by(id: library_id) if library_id
def perform(bgg_username)
library = Library.find_or_create_by(bgg_username: bgg_username)
bgg_user_library = BggApi.new.collection({ username: bgg_username })
existing_games_array = []
existing_games_array += library.games.map { |game| game.bgg_id } if library
existing_games_array = library.games.map { |game| game.bgg_id }
collection_array = bgg_user_library["item"].map { |game| game["objectid"].to_i }
collection_array -= existing_games_array
LibrariesFetcher.perform_async(collection_array, library_id)
LibrariesFetcher.perform_async(collection_array, library.id)
end
end

0 comments on commit f41bfbc

Please sign in to comment.