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

fix: delete deletable tilesets and tiles when deleting style #47

Merged
merged 19 commits into from
Jul 28, 2022

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Jul 14, 2022

Fixes #3

potentially running into an issue with the statements that I use to delete the tilesets. see WiseLibs/better-sqlite3#842 for details

@achou11 achou11 changed the title wip: delete deletable tilesets + tiles when deleting style wip: delete deletable tilesets and tiles when deleting style Jul 14, 2022
@achou11 achou11 force-pushed the ac/fully-delete-styles branch 2 times, most recently from 3fc80f0 to d8b3790 Compare July 26, 2022 14:36
@achou11 achou11 changed the title wip: delete deletable tilesets and tiles when deleting style fix: delete deletable tilesets and tiles when deleting style Jul 26, 2022
@achou11 achou11 requested a review from gmaclennan July 26, 2022 16:39
@achou11 achou11 marked this pull request as ready for review July 26, 2022 16:39
src/api.ts Outdated
Comment on lines 971 to 983
db.prepare(
`
CREATE VIEW DeletableTilesetIds AS
SELECT SourceToTilesetIdOuter.value AS tilesetId, Style.id AS styleId
FROM Style, json_each(Style.sourceIdToTilesetId, '$') AS SourceToTilesetIdOuter
JOIN (
SELECT SourceToTilesetIdInner.value AS tilesetId, COUNT(SourceToTilesetIdInner.value) AS freq
FROM Style, json_each(Style.sourceIdToTilesetId, '$') AS SourceToTilesetIdInner
GROUP BY SourceToTilesetIdInner.value
) AS TilesetIdFreq ON SourceToTilesetIdOuter.value = TilesetIdFreq.tilesetId
WHERE freq = 1;
`
).run()
Copy link
Member Author

@achou11 achou11 Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have no idea if there's a best practice around using views 🤷 at the moment, we create a view, run some statements using it, then delete it

also, view statements can't take params, which would've made this + the following statements a little less verbose

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick thoughts based on 5 mins looking at this. Do we already have / plan to add a deleteTileset function? Does it also delete all tiles that are part of that tileset?
I think that rather than trying to do everything in a single transaction (which I know has the advantage of being atomic), we separate this out:

  1. Query the tilesetIds that need to be deleted
  2. Call api.deleteTileset() on each of those ids (also handles tiledata deletions?)
  3. Delete the style and other resources (offline areas, sprites)

That will maybe make this more manageable? And avoid re-implementing logic in deleteTileset and deleteStyle.

Comment on lines 959 to 961
db.prepare(
'DELETE FROM Import WHERE areaId IN (SELECT id FROM OfflineArea WHERE styleId = ?)'
).run(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to delete anything from the import table? I guess we could, but it's fine I think to keep that record in there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the offline areas table? thought it would make sense to delete there, but in order to do that, we'd need to either delete the associated records in the import table, or update the import table to dereference the offline areas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point, let's delete the imports too.

@achou11
Copy link
Member Author

achou11 commented Jul 26, 2022

yeah we already have something for that. not sure it deletes the tiles though at the moment. will look into it!

@achou11
Copy link
Member Author

achou11 commented Jul 26, 2022

yeah we already have something for that. not sure it deletes the tiles though at the moment. will look into it!

was wrong about this, we don't have an implementation for deleting tilesets. something to work on!

achou11 and others added 11 commits July 26, 2022 15:29
Just a hunch, wondering if having so many open connections to the same DB is causing the errors?
…-server into pr/achou11/47

* 'ac/fully-delete-styles' of github.com:digidem/mapeo-map-server:
  remove unused deleteTileset method
  feat: add offline sprite support (#42)
  improve test for style deletion
* master:
  fix: Fix v8 error with graceful onClose cleanup (#53)
  chore: simplify listStyles SQL (#52)
@gmaclennan
Copy link
Member

I think this is good to go now.

@achou11 achou11 merged commit 2621c99 into master Jul 28, 2022
@achou11 achou11 deleted the ac/fully-delete-styles branch July 28, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add delete route for styles
2 participants