-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Add ability to re-map comments to different URLs #412
Comments
@akosourov - pinging, in case you have time and want to deal with this one. Should be close to the other things you helped with. |
@umputun Yes, that's interesting. I'm going to dive into current version of remark to see how it could be implemented (from my point of view) and return with suggestions |
My thoughts about implementation details:
@umputun What do you think about this ideas? If it is not clear I can write PR to show what I mean :) |
Sure. If we do it as a part of the importer, it should be mapped before
Actually, it should be both. I.e. ability to map individual urls as well as ability to remap with patterns, like domain. Probably can be done with some simple pattern matching, and I think we can even go crazy and support regex, but practically example.com/* -> example2.com/* should be sufficient as the only pattern we care about.
I'd call such interface UrlMapper, but if you like Converter - up to you.
Not sure why would we want to do it. To me, it sounds like the all we need is to inject UrlMapper into
I don't see a reason why not to make it an interface. Will make testing easier, and we could mock it in any way we like. Generally speaking, this new mapper controller will be very similar to the current |
It's not clear for me how to inject UrlMapper into NativeImporter in new controller when request is being handled without changing interface (or without adding a new interface which defines possibility to import & url mapping). If I understand correctly your suggestion is to build UrlMapper once when application objects are build (on prepare app step) and inject it to NativeImporter and pass it to Migrator struct (which holds controllers). But Migrator struct defines NativeImporter as Importer interface. When url-mapping request will being handled I need a way to build UrlMapper from request body, pass it to NativeImporter and call NativeImporter.Import. I can suggest to define new interface which declares import & url mapping possibility, something like
declare it in Migrator.NativeImporter field and extend NativeImporter to implement both Import and MapImporter interface |
Kind of. My suggestion was to initialize
NativeImporter still implements Importer interface, but internally it has UrlMapper field. The real question is how to set mapping rules dynamically, i.e. how the controller can pass those rules to the importer. However, after some quick thinking, I believe we can do it even simpler. Currently, both Exporter and Importer accept io.Reader and io.Writer as a part of the signature. It should be possible to wrap/decorate either one of them with an adopter doing url rewrite for the data passed in. I mean, smth like
pls note: the thinking process was really qucik, so i could be missing something. Feel free to object/critisize this aproach |
I'll try to do via migrator.WithMapper as you suggested without touching interface. Thank for idea. |
@umputun I've added /convert controller which performs possible url remap ability. |
Looking good, much simpler and easier to understand, very nice.
The reason why I suggested to pass the mapper into migrator and not to create it on demand is the ability to change/mock the implementation and, generally speaking, avoid tight coupling between controller and mapper implementation. However, if you don't see a simple way to construct/initialize the mapper with a concrete reader I don't have a big problem with the current implementation and can live with this. One note - convert controller seems to create a temporary export file in order to run mapped importer. Probably it can be eliminated as they all are just readers/writers and
This would be nice to have. I think you will also need 'convert/wait' for this |
Ok, I got it why it is better. I'll change it
I thought about it but if I understand correctly this stream-like approach won't work because when exporter will read portion of data from source (from db) and push it to pipe (to importer) the importer delete all data from source. And exporter will be stopped. This delete action defined here. |
yeah, makes sense. |
@umputun Could you see pr #431 ? It is not already finished yet, but shows main approach. I've moved mapper creation to migrator struct (from build it on demand on every request to build it once on start).
What do you think about use And I have another question about naming. I named /convert API because probably this API could do more complex comment changes. But I'm not sure is it ok to name it so broad, maybe /remap or similar would better. If rest is ok I'll add command for run /convert. |
I have added comments. Hopefully, you can see it, I never know if github shows them to the author or just to me
It is fine, but the path will be misleading in this case. Probably we could change it to just /wait and document the nature, i.e. "used to wait for completion for any async migration ops" |
yeah, remap sounds better to me |
Yes, I see comments and get email notifications, thanks for feedback |
done with #431 |
Sometimes users may need to change linkage between posts and comments. One case we already had (see #411). Another valid reason - blog/site changed domain or url pattern.
To address it we need some way to alter the location. I don't think we want to extend storage,
store.service
and the api with such functionality, but rather perform the export-mapper-import sequence.The mapper will accept input (file? request body?) as a list of "from-url:to-url" pairs and will change all locationw as a part of
migrator
run. Not sure if we need it in exportrer, importer or maybe in bothThe text was updated successfully, but these errors were encountered: