<?xml version="1.0" encoding="utf-8"?>
  <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
  <title>Мультиблог 4X_Pro : Альтернативные технологии для Small Web</title>
  <link>https://4xpro.ru/alternative-internet/</link>
  <description>Для тех, кому не нравится, во что превратился обычный Интернет. Обсуждаем Fediverse, IndieWeb, yggdrasil, gemini и тому подобное</description>
  <lastBuildDate>Mon, 23 Nov 2026 14:38:14 +0000</lastBuildDate>
  <atom:link href="https://4xpro.ru/alternative-internet/rss.htm" rel="self" type="application/rss+xml" />
  <generator>Intellect Board 3 Pro</generator> <item>
          <title>↳Как выяснилось, дело не только (и даже не столько) в кривом JOINе…</title>
          <link>https://4xpro.ru/alternative-internet/akkoma-scale/post-12207.htm</link>
          <description><![CDATA[<div class="p_data"><img src="https://4xpro.ru/f/av/4.jpg" alt="4X_Pro" style="height: 24px; width: 24px; float: left" height="24" width="24"/> <strong>4X_Pro</strong><br /></div><br /><div class="p_text"><p>Как выяснилось, дело не только (и даже не столько) в кривом JOINе, сколько в том, что по непонятным причинам безумно разрослась база данных. Вчера обнаружил, что в ней примерно 480 тыс. пользователей (при том, что локальных &mdash; всего около 200, из них бо́льшая часть &mdash; боты). И теперь не понимаю, это боты активно ходили по чужим профилям, что так наполнили базу, или же она сама постепенно наполняется при формировании глобальной ленты?&nbsp;Причём когда я прогнал запрос для удаления пользователей, с которыми локальные никак не связаны (то есть на этого пользователя никто не подписан, не игнорирует и т.п.), в базе осталось всего около тысячи.<br>
Если кому нужен запрос, он такой:&nbsp;<br>
<br>
</p><p class="intb_wrap_code"><code>
DELETE FROM users
WHERE id IN (
&nbsp; &nbsp; SELECT u.id
&nbsp; &nbsp; FROM users u
&nbsp; &nbsp; WHERE u.local = false
&nbsp; &nbsp; &nbsp; -- 1. Ни один локальный пользователь не подписан на этого удалённого пользователя
&nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM following_relationships fr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users follower ON fr.follower_id = follower.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE fr.following_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND follower.local = true
&nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; -- 2. Локальный пользователь не блокировал/не мьютил этого пользователя
&nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM user_relationships ur
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users local_u ON ur.source_id = local_u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE ur.target_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND local_u.local = true
&nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; -- 3. Этот пользователь не блокировал локального пользователя
&nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM user_relationships ur
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users local_u ON ur.target_id = local_u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE ur.source_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND local_u.local = true
&nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; LIMIT 500
);

</code></p><br>
LIMIT 500 добавлен для того, чтобы база не блокировалась надолго тяжёлыми запросами на удаление. Выполнять запрос имеет смысл в цикле:<br>
<br>
<p class="intb_wrap_code"><code>
while true; do
&nbsp; &nbsp; DELETED=$(psql -U akkoma -d akkoma -t -A -c "
&nbsp; &nbsp; &nbsp; &nbsp; WITH deleted AS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM users
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE id IN (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM users u
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE u.local = false
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM following_relationships fr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users follower ON fr.follower_id = follower.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE fr.following_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND follower.local = true
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM user_relationships ur
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users local_u ON ur.source_id = local_u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE ur.target_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND local_u.local = true
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND NOT EXISTS (
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM user_relationships ur
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOIN users local_u ON ur.target_id = local_u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE ur.source_id = u.id
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND local_u.local = true
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LIMIT 500
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RETURNING 1
&nbsp; &nbsp; &nbsp; &nbsp; )
&nbsp; &nbsp; &nbsp; &nbsp; SELECT count(*) FROM deleted;
&nbsp; &nbsp; ")
&nbsp; &nbsp; echo "Удалено в этой пачке: $DELETED"
&nbsp; &nbsp; if [ "$DELETED" -eq "0" ]; then
&nbsp; &nbsp; &nbsp; &nbsp; break
&nbsp; &nbsp; fi
&nbsp; &nbsp; sleep 1
done

</code></p><br>
</div>]]></description>
          <dc:creator>4X_Pro</dc:creator>
          <pubDate>Mon, 23 Nov 2026 14:38:14 +0000</pubDate><guid>https://4xpro.ru/alternative-internet/akkoma-scale/post-12207.htm</guid>
          </item> <item>
          <title>↳Выяснил, из-за чего такие проблемы. Оказывается…</title>
          <link>https://4xpro.ru/alternative-internet/akkoma-scale/post-12197.htm</link>
          <description><![CDATA[<div class="p_data"><img src="https://4xpro.ru/f/av/4.jpg" alt="4X_Pro" style="height: 24px; width: 24px; float: left" height="24" width="24"/> <strong>4X_Pro</strong><br /></div><br /><div class="p_text"><p>Выяснил, из-за чего такие проблемы. Оказывается, там JOIN двух главных таблиц (objects and activities) делается по JSON-столбцам! А такие JOINы, хоть это столбец типа JSONB с индексами, делаются существенно дольше обычных. Интересно, почему нельзя было вынести в activities затронутый объект в отдельный столбец? Лень разработчика или какие-то объективные причины?</p></div>]]></description>
          <dc:creator>4X_Pro</dc:creator>
          <pubDate>Mon, 16 Nov 2026 08:42:56 +0000</pubDate><guid>https://4xpro.ru/alternative-internet/akkoma-scale/post-12197.htm</guid>
          </item></channel></rss>