NewsCrawler.org

How mixi2 built its feature to import past posts from an X archive

Xで積み重ねた日々をmixi2へ。過去ポストのインポート機能ができるまで
Image: zenn.dev

A mixi2 engineer explains how the team built a feature that imports posts from a downloaded X archive into mixi2. The work started from mixi2's calendar, which lets users look back at their past posts day by day, and the import was prototyped first with the specification refined from the working result. The X archive ZIP holds tweets.js files whose post data is a JavaScript variable containing JSON, so the prefix is stripped off to read post IDs, timestamps and text, while the shortened https://t.co/... URLs have to be expanded and HTML entities decoded. Images are matched to posts by combining the post ID with the media file name, and videos by comparing the video URL candidates with the files in the ZIP.

X allows 140 characters in Japanese, 280 for English-only text and 25,000 with X Premium, while mixi2's limit is 149.3 characters, so overflowing text is cut and closed with “…” and a link to the original post, which also fits inside the limit. The team decided that imported posts appear in the profile, calendar and search but are not delivered to follower timelines, trigger no notifications and do not count toward the posting streak[1], the “834 days of consecutive posting” counter in mixi2. Replies and reposts are not imported, quote posts come over as the user's own text plus a link, and mentions are left as plain text because the same handle on X and mixi2 is not always the same person.

After a report that one X archive download was split into two files of an estimated 50GB and an estimated 15GB, the ZIP is uploaded directly from the client to S3 with multipart upload[2], opened as a file through S3 Files and zip.OpenReader without being loaded into memory, and its post data is split into chunks of up to 1,000 posts saved as JSONL[3] files. A table mapping X post IDs to mixi2 post IDs, written in the same transaction as the post itself, gives the import idempotency[4] so reruns skip posts that were already created, and one failed post does not stop the rest, with results tallied as success, failure or skipped and reported to the user. Imported posts keep their original X timestamps so they line up on the right calendar days and in the profile, and search is still being fixed to index them by those dates too.

Read the original zenn.dev

Sources

  • Zenn JA

    Xで積み重ねた日々をmixi2へ。過去ポストのインポート機能ができるまで

    12 likes0 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page