Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects imported could have no Games and clutter the database #104

Closed
skjiisa opened this issue Sep 15, 2020 · 2 comments · Fixed by #120
Closed

Objects imported could have no Games and clutter the database #104

skjiisa opened this issue Sep 15, 2020 · 2 comments · Fixed by #120
Labels
bug Something isn't working
Milestone

Comments

@skjiisa
Copy link
Owner

skjiisa commented Sep 15, 2020

If JSON is improperly formatted and does not contain any Games, it could be imported and loaded into the database without ever being able to access it.

@skjiisa skjiisa added the bug Something isn't working label Sep 15, 2020
skjiisa added a commit that referenced this issue Sep 15, 2020
Filter Mods list by Game

Note that existing Mods will become inaccessible (related to #104)
There has been no release with mods yet, so I'm considering this to be OK.
@skjiisa
Copy link
Owner Author

skjiisa commented Sep 16, 2020

Since I had Mods with no games in my install of the app, I simply threw this at the bottom of the preloadData() function in the app delegate to get all of the mods added to the Skyrims.

let context = CoreDataStack.shared.mainContext
let modsFR: NSFetchRequest<Mod> = Mod.fetchRequest()
let mods = try? context.fetch(modsFR)

let gamesFR: NSFetchRequest<Game> = Game.fetchRequest()
let allGames = try? context.fetch(gamesFR)
let skyrims = allGames?.filter { $0.name?.lowercased().contains("skyrim") ?? false }

for mod in mods ?? [] {
    for skyrim in skyrims ?? [] {
        mod.addToGames(skyrim)
    }
}

@skjiisa
Copy link
Owner Author

skjiisa commented Oct 5, 2020

A cleanup script could run after imports to remove objects with no games. This could be done on the background thread the import happens on so that when the prompt shows the list of imported objects, invalid objects won't be included.

@skjiisa skjiisa added this to the v1.3 milestone Oct 13, 2020
@skjiisa skjiisa mentioned this issue Dec 14, 2020
@skjiisa skjiisa linked a pull request Dec 15, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant