-
-
Notifications
You must be signed in to change notification settings - Fork 229
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 redirects table and migration script #3185
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
Important Auto Review SkippedAuto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings. Please check the settings in the CodeRabbit UI or the To trigger a single review, invoke the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
7b647a4
to
f6a80bd
Compare
02371aa
to
68c10b8
Compare
f6a80bd
to
5912d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice to finally pull this into our DB :)
I think it would be good to do a bit more cleanup in the sync script:
- remove trailing slashes in source
- remove trailing slashes in target unless it is the root url (/)
- get rid of chains. We currently have 28 redirects where the target of one is the source of another (i.e. A.target == B.source - see query below). I think it would be nice to resolve these to the final target before storing them in our DB
To see the chains, this query is useful:
select
hop1.source as initialSource,
hop1.target as intermediateTarget,
hop2.target as finalTarget,
hop3.target as veryFinalTarget
from
redirects hop1
inner join redirects hop2 on
hop2.source = hop1.target
left join redirects hop3 on
hop2.target = hop3.source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
68c10b8
to
d6079f7
Compare
5912d1d
to
67d13f9
Compare
d6079f7
to
9d9a459
Compare
67d13f9
to
90655d5
Compare
✅ (see code comments for further edge cases)
✅ I adapted and reused the internal resolver logic for this |
9d9a459
to
4f82e1a
Compare
90c76db
to
2785a24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good! Arguable existingRedirectsFromDb should be a set but the runtime difference is probably negligible :)
@danyx23 yes at that scale any kind of optimization probably doesn't change much, especially given that we won't be running this script more than a handful of times. Out of curiosity though, do you mean doing something like what you did there? owid-grapher/db/syncPostsToGrapher.ts Lines 219 to 229 in 2785a24
|
4f82e1a
to
6a12c91
Compare
2785a24
to
71ad893
Compare
6a12c91
to
b940bbc
Compare
71ad893
to
e41d3a3
Compare
b940bbc
to
7e1c618
Compare
e41d3a3
to
88727a1
Compare
This PR adds a new
redirects
table to hold redirects currently stored in the Wordpress database.It also adds a migration script to import Wordpress redirects:
syncRedirectsToGrapher
:node itsJustJavascript/baker/syncRedirectsToGrapher.js
Testing
The number of enabled redirected in the Wordpress table is identical to the number of redirects in the new table after running the migration script.