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

Short links #544

Merged
merged 18 commits into from
Aug 17, 2023
Merged

Short links #544

merged 18 commits into from
Aug 17, 2023

Conversation

clbn
Copy link
Contributor

@clbn clbn commented Nov 4, 2021

This is the server-side part of the Short Links feature.

  • Add options for the short links to the config file
  • Add the table to the DB
  • Add code for generating short IDs when creating posts
  • Add shortId prop to Post objects in API responses
  • Update single-post API endpoint (GET /v2/posts/:postId) to accept post's short ID along with the long ID
  • Tests!
  • Update backlinks extraction
  • Write a script for backfilling short IDs (for old posts)

Part 2:

  • Add support to EventService (notifications)
  • Add support for realtime events
  • Add support to bin/reindex_backlinks

types/config.d.ts Outdated Show resolved Hide resolved
data_transfer/PgAdapter.js Outdated Show resolved Hide resolved
data_transfer/PgAdapter.js Outdated Show resolved Hide resolved
@clbn clbn force-pushed the short-links branch 2 times, most recently from 3eab565 to 6554ea0 Compare January 19, 2022 15:54
@clbn clbn changed the title Short links (draft) Short links Jan 19, 2022
@clbn clbn mentioned this pull request Jan 19, 2022
12 tasks
@clbn clbn marked this pull request as ready for review January 19, 2022 16:21
@clbn clbn force-pushed the short-links branch 3 times, most recently from 44358fc to ae6669e Compare January 25, 2022 22:57
@clbn clbn force-pushed the short-links branch 6 times, most recently from 0468ed4 to e497690 Compare July 25, 2023 19:55
@@ -16,6 +16,11 @@ export function extractUUIDs(text: string | null): UUID[] {
return text ? [...text.matchAll(uuidRe)].map((m) => m[0]).filter(onlyUnique) : [];
}

export const shortLinkRe = /\/[A-Za-z0-9]{3,25}\/([0-9a-f]{6,10})/gi;
Copy link
Member

Choose a reason for hiding this comment

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

Тут ещё надо минус учесть, для groupnames

Copy link
Member

Choose a reason for hiding this comment

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

И не надо ли границу слов как-то проверять? А то оно и в посторонних урлах может сработать. Или понадеемся, что 6 символов с нашими id-ами вряд ли совпадут?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Тут непонятно. С одной стороны, мы вроде как хотели всю эту логику на клиент отдать. С другой стороны, из-за бэклинков вот приходится делать парсинг на сервере. Надо бы как-то формализовать это, чтоб алгоритм на сервере и клиенте — ну, не совпадали, но хоть как-то были близки.

Или не париться, потому что к большому беспорядку false positives не приведут…

@clbn clbn force-pushed the short-links branch 2 times, most recently from 63ca674 to 38aba98 Compare July 25, 2023 22:35
bin/reindex_backlinks.js Outdated Show resolved Hide resolved
@clbn clbn force-pushed the short-links branch 3 times, most recently from 2f8ac64 to abf46f7 Compare August 16, 2023 09:01
clbn added 17 commits August 17, 2023 00:08
We define short_comment_id as two characters of the UUID, followed by
the hex-encoded seq_number.
This change adds parsing of short comment links (e.g. `/user/9bac13#ad2b`)
to EventService a.k.a Notifications. That is the only place we need
special support. Other relevant server parts (backlinks table, reindex
script, realtime events) only need the post_id anyway (for now), so they
work with such links already, not caring about the comment_id part.
Before:
- generate shortId on READ
- use 2 chars of UUID followed by seqNumber (resulting length is 3+)

After:
- generate shortId on WRITE, and put into table `comments` (column `short_id`)
- use randomly generated hex string (resulting length is 4-6)
@clbn clbn force-pushed the short-links branch 2 times, most recently from 38dc55d to ea7805b Compare August 16, 2023 22:17
davidmz
davidmz previously approved these changes Aug 17, 2023
@davidmz davidmz merged commit 18e5adf into stable Aug 17, 2023
18 checks passed
@clbn clbn deleted the short-links branch August 17, 2023 18:00
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.

2 participants