Fix direction of fake edges

- batch -> insertion fake edge
 - Connecting insertion events' `prev_events` successors -> insertion event

---

 - batch -> insertion fake edge
 - Connecting insertion events' `prev_events` successors -> insertion event

```
backfill sorted_events=[
  "event_id=$RQU5oBY9oHveDdx1X4FZs6BWzBqrGnbxQCZfNF4OEmw,depth=11,body=Message 1 (eventIDsAfter),prevs=['$44dIgrZ6WEBaxnCxiulvFQmLRlgIF2c2LHxwVZ39BhY']",
  "event_id=$44dIgrZ6WEBaxnCxiulvFQmLRlgIF2c2LHxwVZ39BhY,depth=10,body=Message 0 (eventIDsAfter),prevs=['$G00qI6L-Jem6u0rM73WAgtl3e27WFREG_IqXBK3rBVY']",
  "event_id=$Bb7NKUT_EJEIYJucAJvsm3IGWOHPV5HjT9sFBH4cgJ0,depth=10,body=org.matrix.msc2716.insertion,prevs=['$G00qI6L-Jem6u0rM73WAgtl3e27WFREG_IqXBK3rBVY']",
  "event_id=$DD2ibvlCDuylHLA5XHpzbWgplgANwmvy_qRGIz6obgU,depth=10,body=org.matrix.msc2716.batch,prevs=['$JfIXG5RA3SubwPx3qekrP7p7TL84M-EMXyrWUPGEJqE']",
  "event_id=$JfIXG5RA3SubwPx3qekrP7p7TL84M-EMXyrWUPGEJqE,depth=10,body=Historical 99 (batch=0),prevs=['$JMMtj_q0q-o3sgMjGtUDot_vjIBS1fu7pMFIVIKW8XU']",
  "event_id=$JMMtj_q0q-o3sgMjGtUDot_vjIBS1fu7pMFIVIKW8XU,depth=10,body=Historical 98 (batch=0),prevs=['$lCpKjiG2aZzjSvL4mu3BijwjsuGADKfP6CmB6S_9TeI']",
  "event_id=$lCpKjiG2aZzjSvL4mu3BijwjsuGADKfP6CmB6S_9TeI,depth=10,body=Historical 97 (batch=0),prevs=['$2e-t0QWqLfVJz2fdwbwAuT7HpT2awCyFhtR35VPUx0Q']",
  "event_id=$2e-t0QWqLfVJz2fdwbwAuT7HpT2awCyFhtR35VPUx0Q,depth=10,body=Historical 96 (batch=0),prevs=['$3tMaM3-QgXlRaGWzkcKg8VOooUETwADMmvC8LgPHi3k']",
  "event_id=$3tMaM3-QgXlRaGWzkcKg8VOooUETwADMmvC8LgPHi3k,depth=10,body=Historical 95 (batch=0),prevs=['$sWNiiKCpV6jaMOBrJPKSnmhfm1HvzQX5reT9cNGTgkk']",
  "event_id=$sWNiiKCpV6jaMOBrJPKSnmhfm1HvzQX5reT9cNGTgkk,depth=10,body=Historical 94 (batch=0),prevs=['$b23cNluaxei15QPBanvua5F690RJdnL4yCq-3MAbKyc']",
  "event_id=$b23cNluaxei15QPBanvua5F690RJdnL4yCq-3MAbKyc,depth=10,body=Historical 93 (batch=0),prevs=['$mlWvqR2MWITXVBZfeVLcujmVAzBvkkDdP6oSz3eSwUg']",
  "event_id=$mlWvqR2MWITXVBZfeVLcujmVAzBvkkDdP6oSz3eSwUg,depth=10,body=Historical 92 (batch=0),prevs=['$wlVdFpoXlPWoajb33gizlhlft5k-tVwGUpmMsmcoHPU']",
  "event_id=$wlVdFpoXlPWoajb33gizlhlft5k-tVwGUpmMsmcoHPU,depth=10,body=Historical 91 (batch=0),prevs=['$v6VMFCnyQkl16tZCVu7J_-Nst_NRXXaQd2efn2TUpEE']",
  "event_id=$v6VMFCnyQkl16tZCVu7J_-Nst_NRXXaQd2efn2TUpEE,depth=10,body=Historical 90 (batch=0),prevs=['$ooH_Jq5JLVIkIB9TpsltyHtqtn7KNxDIc_xYUcBUsAA']",
  "event_id=$ooH_Jq5JLVIkIB9TpsltyHtqtn7KNxDIc_xYUcBUsAA,depth=10,body=Historical 89 (batch=0),prevs=['$iK_6DSB9OgXzFNQ1qEZo_42ifWrX1xwUKs_qFKZT8Uo']",
  "event_id=$iK_6DSB9OgXzFNQ1qEZo_42ifWrX1xwUKs_qFKZT8Uo,depth=10,body=Historical 88 (batch=0),prevs=['$LKnAV4et1stXQRkd_dg0XOK5kNXFyFYQOgx5wdSQB34']",
  "event_id=$LKnAV4et1stXQRkd_dg0XOK5kNXFyFYQOgx5wdSQB34,depth=10,body=Historical 87 (batch=0),prevs=['$vvtLzYBovfNjm-aU5o5JF6TumBAzrBbzrMVrqA43cmE']",
  "event_id=$vvtLzYBovfNjm-aU5o5JF6TumBAzrBbzrMVrqA43cmE,depth=10,body=Historical 86 (batch=0),prevs=['$yYyBW-D_3XN6aYyXeRJKQYN1hJyswh9kUe2Q3kk_auA']",
  "event_id=$yYyBW-D_3XN6aYyXeRJKQYN1hJyswh9kUe2Q3kk_auA,depth=10,body=Historical 85 (batch=0),prevs=['$_1yK-Gzkabr_ZKMRFHlJMat943MjCznY2YN2WPExrtY']",
  "event_id=$_1yK-Gzkabr_ZKMRFHlJMat943MjCznY2YN2WPExrtY,depth=10,body=Historical 84 (batch=0),prevs=['$CZSLI1NUX9gWptZT_i52oyCfQpH5rOlPFSgmSjD4a-Q']",
  "event_id=$CZSLI1NUX9gWptZT_i52oyCfQpH5rOlPFSgmSjD4a-Q,depth=10,body=Historical 83 (batch=0),prevs=['$093Wua4ZaJLX4uRYuL89y3t47jntwceo0ReVGM-_WNE']",
  "event_id=$093Wua4ZaJLX4uRYuL89y3t47jntwceo0ReVGM-_WNE,depth=10,body=Historical 82 (batch=0),prevs=['$wA7OKTWe6BMbXustd4WBLTJ2fBIY4RLeOstoKaaiIwg']",
  "event_id=$wA7OKTWe6BMbXustd4WBLTJ2fBIY4RLeOstoKaaiIwg,depth=10,body=Historical 81 (batch=0),prevs=['$ZUVoXb9Or3HAeZVM5nKYUp1-mcizUyGuQHuUaRTEf8s']",
  "event_id=$ZUVoXb9Or3HAeZVM5nKYUp1-mcizUyGuQHuUaRTEf8s,depth=10,body=Historical 80 (batch=0),prevs=['$ul_NFiXrTv6S-YseztgF5fpKx-_gXeQ7C9XF_TdcCqM']",
  "event_id=$ul_NFiXrTv6S-YseztgF5fpKx-_gXeQ7C9XF_TdcCqM,depth=10,body=Historical 79 (batch=0),prevs=['$9zzm0Mr6wn2W5EKl7t0AmGqJntslGV9Telo6rP9DeZg']",
  "event_id=$9zzm0Mr6wn2W5EKl7t0AmGqJntslGV9Telo6rP9DeZg,depth=10,body=Historical 78 (batch=0),prevs=['$LsfJ_IpS4y1mWjdLFsod16JBS2B2j0XO3BCMEtXaigk']",
  "event_id=$LsfJ_IpS4y1mWjdLFsod16JBS2B2j0XO3BCMEtXaigk,depth=10,body=Historical 77 (batch=0),prevs=['$hfdqS5ARU7roPsWgGS8RXsog_m0P7vOc1UMdmKju0aw']",
  "event_id=$hfdqS5ARU7roPsWgGS8RXsog_m0P7vOc1UMdmKju0aw,depth=10,body=Historical 76 (batch=0),prevs=['$h4ZA91X45b8aNuMjz_xC1457mw2h6_MTSqvv6MVH8tU']",
  "event_id=$h4ZA91X45b8aNuMjz_xC1457mw2h6_MTSqvv6MVH8tU,depth=10,body=Historical 75 (batch=0),prevs=['$qvxKJlvqC0gaRP7mRjO-yMD4Zzt42dkd7dqZSs-v-Fk']",
  "event_id=$qvxKJlvqC0gaRP7mRjO-yMD4Zzt42dkd7dqZSs-v-Fk,depth=10,body=Historical 74 (batch=0),prevs=['$kgMcrid7-aqUIzDzjouB3HQKIGh2h-6Iop6WK08KCkc']",
  "event_id=$kgMcrid7-aqUIzDzjouB3HQKIGh2h-6Iop6WK08KCkc,depth=10,body=Historical 73 (batch=0),prevs=['$_ssYYwoWm7OOjhYwkZxQKOMq7maygenjjLJBypuA3N8']",
  "event_id=$_ssYYwoWm7OOjhYwkZxQKOMq7maygenjjLJBypuA3N8,depth=10,body=Historical 72 (batch=0),prevs=['$1OAjmvRdC67suR_wlrgbQDzOFJZxAnE4RZyKt4Khq9M']",
  "event_id=$1OAjmvRdC67suR_wlrgbQDzOFJZxAnE4RZyKt4Khq9M,depth=10,body=Historical 71 (batch=0),prevs=['$1cpjOXZwqsZzZ643qAkcnEc3Mjgl1n_WPfeVaovxE0g']",
  "event_id=$1cpjOXZwqsZzZ643qAkcnEc3Mjgl1n_WPfeVaovxE0g,depth=10,body=Historical 70 (batch=0),prevs=['$qYsfdlkVwJDtvjGHQtJATjglCIUzj11Cu7Kt70Qpa00']",
  "event_id=$qYsfdlkVwJDtvjGHQtJATjglCIUzj11Cu7Kt70Qpa00,depth=10,body=Historical 69 (batch=0),prevs=['$xwkLzZQX2w1rS9IbSburCCNy9g_3GA5cxR2Dd1AiDEo']",
  "event_id=$xwkLzZQX2w1rS9IbSburCCNy9g_3GA5cxR2Dd1AiDEo,depth=10,body=Historical 68 (batch=0),prevs=['$RUjVghSfYx0Rz-HMW7pFUjVL7gjnDh5FhrzmizwRSg4']",
  "event_id=$RUjVghSfYx0Rz-HMW7pFUjVL7gjnDh5FhrzmizwRSg4,depth=10,body=Historical 67 (batch=0),prevs=['$xFM3GD0jHQ2sV_w-m996lYIj6bBy3e4zoo4zba7KK94']",
  "event_id=$xFM3GD0jHQ2sV_w-m996lYIj6bBy3e4zoo4zba7KK94,depth=10,body=Historical 66 (batch=0),prevs=['$P9rG_KsdrP29_nrUhVNwDXxEj6TtcAHYMiEPjTECuyI']",
  "event_id=$P9rG_KsdrP29_nrUhVNwDXxEj6TtcAHYMiEPjTECuyI,depth=10,body=Historical 65 (batch=0),prevs=['$fG9vXCIp3ymBUSQGfxuQyHjXvwfaz0i-Al5PZER5q6Y']",
  "event_id=$fG9vXCIp3ymBUSQGfxuQyHjXvwfaz0i-Al5PZER5q6Y,depth=10,body=Historical 64 (batch=0),prevs=['$ZppkvSCfh7zKOSOIaAzzOM13xzO3c46HlvAt1ogqxSI']",
  "event_id=$ZppkvSCfh7zKOSOIaAzzOM13xzO3c46HlvAt1ogqxSI,depth=10,body=Historical 63 (batch=0),prevs=['$XJgjPkRjlTh04CAXr_7doyRn9uP6Q2BRBS5ogIxxgq4']",
  "event_id=$XJgjPkRjlTh04CAXr_7doyRn9uP6Q2BRBS5ogIxxgq4,depth=10,body=Historical 62 (batch=0),prevs=['$iiC9E-Xbw8DqYLkca_3SYXKP0fyjAO3Rulzl_UMlg_U']",
  "event_id=$iiC9E-Xbw8DqYLkca_3SYXKP0fyjAO3Rulzl_UMlg_U,depth=10,body=Historical 61 (batch=0),prevs=['$JQrY-1YX4u1WLM8pf-YV45wOig2GZmXyLRzQd16lNRY']",
  "event_id=$JQrY-1YX4u1WLM8pf-YV45wOig2GZmXyLRzQd16lNRY,depth=10,body=Historical 60 (batch=0),prevs=['$EZwD8zE9aSg6UYGfT93gAB22vf1EbG2m4rXNWYtDoMM']",
  "event_id=$EZwD8zE9aSg6UYGfT93gAB22vf1EbG2m4rXNWYtDoMM,depth=10,body=Historical 59 (batch=0),prevs=['$MXdmxSkN7gpzy28Rg6Ond0DyVu4a6_NA2PAEh2RGhWE']",
  "event_id=$MXdmxSkN7gpzy28Rg6Ond0DyVu4a6_NA2PAEh2RGhWE,depth=10,body=Historical 58 (batch=0),prevs=['$3qKPpnyChlt2O24cqwF2zHORIvm4zbVwugRtKxkAQAo']",
  "event_id=$3qKPpnyChlt2O24cqwF2zHORIvm4zbVwugRtKxkAQAo,depth=10,body=Historical 57 (batch=0),prevs=['$fZwZ3KIY2HpkBh_-GX762uJlvSDjKx_jkKBmO4XMXbU']",
  "event_id=$fZwZ3KIY2HpkBh_-GX762uJlvSDjKx_jkKBmO4XMXbU,depth=10,body=Historical 56 (batch=0),prevs=['$6S5Ni1dMs9cIWmlGAToAXq9HD19IC3VzPsA6Mpv-99k']",
  "event_id=$6S5Ni1dMs9cIWmlGAToAXq9HD19IC3VzPsA6Mpv-99k,depth=10,body=Historical 55 (batch=0),prevs=['$H_iqXiAxOxF6cEFG8uBIOA4daNZRS-n5BkyIO2TJB1M']",
  "event_id=$H_iqXiAxOxF6cEFG8uBIOA4daNZRS-n5BkyIO2TJB1M,depth=10,body=Historical 54 (batch=0),prevs=['$M_jaKYkmwpIOh5WbYKo7OABADOIde2GL_UpYgy5DKJE']",
  "event_id=$M_jaKYkmwpIOh5WbYKo7OABADOIde2GL_UpYgy5DKJE,depth=10,body=Historical 53 (batch=0),prevs=['$_tY_1OYdYB2e4mX0psdoZXQqbr_nJvdxNErra3vIRHw']",
  "event_id=$_tY_1OYdYB2e4mX0psdoZXQqbr_nJvdxNErra3vIRHw,depth=10,body=Historical 52 (batch=0),prevs=['$8x0ZzHjqduS1SlqKk1F6x1G71bKCFPWbx0nYU90GS8g']",
  "event_id=$8x0ZzHjqduS1SlqKk1F6x1G71bKCFPWbx0nYU90GS8g,depth=10,body=Historical 51 (batch=0),prevs=['$hYNHRnZ2AktMkxjbiPP_yofAOMmRJLy4nN5K-81-yj8']",
  "event_id=$hYNHRnZ2AktMkxjbiPP_yofAOMmRJLy4nN5K-81-yj8,depth=10,body=Historical 50 (batch=0),prevs=['$Aje2Qa0CHNWiAw1HiK-1djoycAhh4UliroN1vAdKIU4']",
  "event_id=$Aje2Qa0CHNWiAw1HiK-1djoycAhh4UliroN1vAdKIU4,depth=10,body=Historical 49 (batch=0),prevs=['$hbkSA7qbBPpEQH77YE2h-XKVgS3qhI3xse3Yg08smuc']",
  "event_id=$hbkSA7qbBPpEQH77YE2h-XKVgS3qhI3xse3Yg08smuc,depth=10,body=Historical 48 (batch=0),prevs=['$N80_1es0l8LAcvslhrbTOddyQ76W3_VLPnXnG5IBEn4']",
  "event_id=$N80_1es0l8LAcvslhrbTOddyQ76W3_VLPnXnG5IBEn4,depth=10,body=Historical 47 (batch=0),prevs=['$rvz1DpQx9HZLbHgZj5Jq3TVoH1WComOP6AWbytDKClQ']",
  "event_id=$rvz1DpQx9HZLbHgZj5Jq3TVoH1WComOP6AWbytDKClQ,depth=10,body=Historical 46 (batch=0),prevs=['$a6ifNO0AizTsP4HnVPD3Zkuqvo-8PnarenXKDUJZvGE']",
  "event_id=$a6ifNO0AizTsP4HnVPD3Zkuqvo-8PnarenXKDUJZvGE,depth=10,body=Historical 45 (batch=0),prevs=['$1WL7whQmdncf8CJ5l38dn_J8PVztPTNNMNS82gltKhw']",
  "event_id=$1WL7whQmdncf8CJ5l38dn_J8PVztPTNNMNS82gltKhw,depth=10,body=Historical 44 (batch=0),prevs=['$yCLNJyVjv2ti71ORpJI1wuyiWWOCG857If5M24eK2c4']",
  "event_id=$yCLNJyVjv2ti71ORpJI1wuyiWWOCG857If5M24eK2c4,depth=10,body=Historical 43 (batch=0),prevs=['$LV_gqx1bl9NHYdifp_v5JA1QE79nwblPe9dY_MKWuFo']",
  "event_id=$LV_gqx1bl9NHYdifp_v5JA1QE79nwblPe9dY_MKWuFo,depth=10,body=Historical 42 (batch=0),prevs=['$TT41-KXnRahtw3bBlgFkaLEvnGtC7BPispoy9LVoSTE']",
  "event_id=$TT41-KXnRahtw3bBlgFkaLEvnGtC7BPispoy9LVoSTE,depth=10,body=Historical 41 (batch=0),prevs=['$X0wtHayfehEhB59jCSI2NSX5LSdgQfMYBy5D5IXerrg']",
  "event_id=$X0wtHayfehEhB59jCSI2NSX5LSdgQfMYBy5D5IXerrg,depth=10,body=Historical 40 (batch=0),prevs=['$ERk1O6FQFNndKxopemlDrzWV_SZ9zvPaK-7cDWc9hOo']",
  "event_id=$ERk1O6FQFNndKxopemlDrzWV_SZ9zvPaK-7cDWc9hOo,depth=10,body=Historical 39 (batch=0),prevs=['$8EltMIaFXj0HYOUsfGwDXs6--yrfI5NvQHbv8okNMbI']",
  "event_id=$8EltMIaFXj0HYOUsfGwDXs6--yrfI5NvQHbv8okNMbI,depth=10,body=Historical 38 (batch=0),prevs=['$8S8FjedOebUYwPFtb7vb-ZzMeYDp7vJRk-OUzau1RlY']",
  "event_id=$8S8FjedOebUYwPFtb7vb-ZzMeYDp7vJRk-OUzau1RlY,depth=10,body=Historical 37 (batch=0),prevs=['$s06MJYSVrGYW73z6hpTeCPDxnuFLkJXWvyym-4RqTXg']",
  "event_id=$s06MJYSVrGYW73z6hpTeCPDxnuFLkJXWvyym-4RqTXg,depth=10,body=Historical 36 (batch=0),prevs=['$fXsHFdVTchw-xmD41v9KC2ZxC5j6-VYRHGdRTw4AxRQ']",
  "event_id=$fXsHFdVTchw-xmD41v9KC2ZxC5j6-VYRHGdRTw4AxRQ,depth=10,body=Historical 35 (batch=0),prevs=['$ETgS3ZdUq57PzCK0ki-oV21XqFBs1nSgv6CHVl1nddw']",
  "event_id=$ETgS3ZdUq57PzCK0ki-oV21XqFBs1nSgv6CHVl1nddw,depth=10,body=Historical 34 (batch=0),prevs=['$GyrVy70TxEH3ARdy1tf-ZuxyWTqY8M4GeD-e0O4bXTs']",
  "event_id=$GyrVy70TxEH3ARdy1tf-ZuxyWTqY8M4GeD-e0O4bXTs,depth=10,body=Historical 33 (batch=0),prevs=['$etOVbOEtwqS-iLZfOWwAWeaf7Nq4h6B0aLTcsL3Fqb4']",
  "event_id=$etOVbOEtwqS-iLZfOWwAWeaf7Nq4h6B0aLTcsL3Fqb4,depth=10,body=Historical 32 (batch=0),prevs=['$jkugW9wPO5-ZTu3pulbPyYUs7MT08q24rSit47W2aiE']",
  "event_id=$jkugW9wPO5-ZTu3pulbPyYUs7MT08q24rSit47W2aiE,depth=10,body=Historical 31 (batch=0),prevs=['$xl5SAerMsKP7xYH7e9B0QyjNGVu1zYN037WcMl6eM7I']",
  "event_id=$xl5SAerMsKP7xYH7e9B0QyjNGVu1zYN037WcMl6eM7I,depth=10,body=Historical 30 (batch=0),prevs=['$epCIEu5hsIrjVfAQ8xwG_w7l2L_GVswFGlOgvKuBOv4']",
  "event_id=$epCIEu5hsIrjVfAQ8xwG_w7l2L_GVswFGlOgvKuBOv4,depth=10,body=Historical 29 (batch=0),prevs=['$W-r7mxy0Yaj7M33JPu3WwCGHZ4zy-r_UsuuSiSbaBNI']",
  "event_id=$W-r7mxy0Yaj7M33JPu3WwCGHZ4zy-r_UsuuSiSbaBNI,depth=10,body=Historical 28 (batch=0),prevs=['$j4NztVmkOMiN4_drb1Hm0EOEh5kDM1r7Vo1jKPlz5iY']",
  "event_id=$j4NztVmkOMiN4_drb1Hm0EOEh5kDM1r7Vo1jKPlz5iY,depth=10,body=Historical 27 (batch=0),prevs=['$QhtQWlhor0qS81fOCmF2UmYSZXrCY2YabQ3Ysk1pvQ8']",
  "event_id=$QhtQWlhor0qS81fOCmF2UmYSZXrCY2YabQ3Ysk1pvQ8,depth=10,body=Historical 26 (batch=0),prevs=['$ICyGlEHUQ2VNNkGL8KfN5v9rbuLZzYQ_LmH-XpKXi-w']",
  "event_id=$ICyGlEHUQ2VNNkGL8KfN5v9rbuLZzYQ_LmH-XpKXi-w,depth=10,body=Historical 25 (batch=0),prevs=['$4WvejXMuOtnrR_npONQHcEptKDb7oeAdzlguCFafXw8']",
  "event_id=$4WvejXMuOtnrR_npONQHcEptKDb7oeAdzlguCFafXw8,depth=10,body=Historical 24 (batch=0),prevs=['$1dQvQ9CXC8jvDir8Qv_qWD1P6669n5Dt2e9MQzWMmus']",
  "event_id=$1dQvQ9CXC8jvDir8Qv_qWD1P6669n5Dt2e9MQzWMmus,depth=10,body=Historical 23 (batch=0),prevs=['$VqYi4klnvQoQapuwcRhVOGpnd8b5JZbhpr0J8bIVq6s']",
  "event_id=$VqYi4klnvQoQapuwcRhVOGpnd8b5JZbhpr0J8bIVq6s,depth=10,body=Historical 22 (batch=0),prevs=['$caikDgtNzU_-uPQvliFV0LaXeD5KxfT42bbYT-tBuz4']",
  "event_id=$caikDgtNzU_-uPQvliFV0LaXeD5KxfT42bbYT-tBuz4,depth=10,body=Historical 21 (batch=0),prevs=['$tAmrVFwIE67VdJdTELUy9dCLX7UnwEQWJQ0szLMLj1I']",
  "event_id=$tAmrVFwIE67VdJdTELUy9dCLX7UnwEQWJQ0szLMLj1I,depth=10,body=Historical 20 (batch=0),prevs=['$moO383nMlO3xQcIcBJRa1ob23aKG_3BboL0VzaEuV9M']",
  "event_id=$moO383nMlO3xQcIcBJRa1ob23aKG_3BboL0VzaEuV9M,depth=10,body=Historical 19 (batch=0),prevs=['$1ZC20pJmFEnjdsp1WeF3Vb786YGxRUN7lVgBuGtbTh0']",
  "event_id=$1ZC20pJmFEnjdsp1WeF3Vb786YGxRUN7lVgBuGtbTh0,depth=10,body=Historical 18 (batch=0),prevs=['$CR5eEOqcjN4M-V4z4pmcGuj4DDZvIXsXJuCGKFCL2bo']",
  "event_id=$CR5eEOqcjN4M-V4z4pmcGuj4DDZvIXsXJuCGKFCL2bo,depth=10,body=Historical 17 (batch=0),prevs=['$5Nt4QouUaxCemiakDvgSau0Awaq2eLiuf_zAotPHrEk']",
  "event_id=$5Nt4QouUaxCemiakDvgSau0Awaq2eLiuf_zAotPHrEk,depth=10,body=Historical 16 (batch=0),prevs=['$bQGGb7wF69JaRvAgcy8YXA--vZxVwIFoQwBxz1JNcc0']",
  "event_id=$bQGGb7wF69JaRvAgcy8YXA--vZxVwIFoQwBxz1JNcc0,depth=10,body=Historical 15 (batch=0),prevs=['$5NTrpJdUTplsV5Pv0h81f10Od7r8b7MByhNP-Hgo5XI']",
  "event_id=$5NTrpJdUTplsV5Pv0h81f10Od7r8b7MByhNP-Hgo5XI,depth=10,body=Historical 14 (batch=0),prevs=['$RlE8jSspaoHviQ64oGYupPalY6iiEOfm6SVKxCFcj5Q']",
  "event_id=$RlE8jSspaoHviQ64oGYupPalY6iiEOfm6SVKxCFcj5Q,depth=10,body=Historical 13 (batch=0),prevs=['$fAjxrhPzB4YdRFSVUrY4dyUX2rs_Og61PlIxutf4cPw']",
  "event_id=$fAjxrhPzB4YdRFSVUrY4dyUX2rs_Og61PlIxutf4cPw,depth=10,body=Historical 12 (batch=0),prevs=['$AiIInms6FQzl0GHYZw38stEFC72Bl9uoW5r7sLBOdiw']",
  "event_id=$AiIInms6FQzl0GHYZw38stEFC72Bl9uoW5r7sLBOdiw,depth=10,body=Historical 11 (batch=0),prevs=['$l5uuVWnK1HYmBpL-X8XGLG-0FzXmrAVDAdFojpD_BnY']",
  "event_id=$l5uuVWnK1HYmBpL-X8XGLG-0FzXmrAVDAdFojpD_BnY,depth=10,body=Historical 10 (batch=0),prevs=['$bq2Cmy1rMLmJRWRek0azb5SE-CBPj-QJ1GB2F6X6pos']",
  "event_id=$bq2Cmy1rMLmJRWRek0azb5SE-CBPj-QJ1GB2F6X6pos,depth=10,body=Historical 9 (batch=0),prevs=['$fNL5PyiTg-FuQaq3rBdqAzVLev7MPo89u5nUGdP5CdY']",
  "event_id=$fNL5PyiTg-FuQaq3rBdqAzVLev7MPo89u5nUGdP5CdY,depth=10,body=Historical 8 (batch=0),prevs=['$FZvdy85_rIB-TgSq2irIGp8TPz3vt3DdEsTlmklxHfE']",
  "event_id=$FZvdy85_rIB-TgSq2irIGp8TPz3vt3DdEsTlmklxHfE,depth=10,body=Historical 7 (batch=0),prevs=['$gibUQn3wnIHPf2CzXr4rVaDd0ozucmpZLTXi69kT4v0']",
  "event_id=$gibUQn3wnIHPf2CzXr4rVaDd0ozucmpZLTXi69kT4v0,depth=10,body=Historical 6 (batch=0),prevs=['$EtLYRN3xJoYCG2f6l3ZNzeFDBVgT0sJSO-5_CWfk62E']",
  "event_id=$G00qI6L-Jem6u0rM73WAgtl3e27WFREG_IqXBK3rBVY,depth=9,body=Message 1 (eventIDsBefore),prevs=['$E9W0RVZ5jf054fUIQPlls4AXPlFcS5sF6iSwdsgpEZ0']",
  "event_id=$EtLYRN3xJoYCG2f6l3ZNzeFDBVgT0sJSO-5_CWfk62E,depth=10,body=Historical 5 (batch=0),prevs=['$6f7SVRgiDAaiqWanvIsjBfJieMdK8fP_t8qalpWDTKo']"
]
```

When only connecting batch -> insertion event:

 - batch -> insertion fake edge

```
backfill sorted_events=[
  "event_id=$vDdCr0f90ey6Pjpw8Ugl2HQf09Rww5x_M8LanATK8VM,depth=10,body=org.matrix.msc2716.insertion,prevs=['$n9kq5qDGfNxKw7_Cb8kIC-9BrQ0Kg_sTWn9_nLwovA4']",
  "event_id=$h9x6BgpQVHF8Jr33ovBjTxDvXYuR6aNyxw2sKWKqu5U,depth=10,body=org.matrix.msc2716.batch,prevs=['$KU7hS3FmvoQaZkOjdWqyuBqBwFvcWdqJEbKvsXAxWgg']",
  "event_id=$KU7hS3FmvoQaZkOjdWqyuBqBwFvcWdqJEbKvsXAxWgg,depth=10,body=Historical 99 (batch=0),prevs=['$N0bxYWNt4qrh3B4ns78nzD_BRSFzMHt1KTynmuIjztQ']",
  "event_id=$N0bxYWNt4qrh3B4ns78nzD_BRSFzMHt1KTynmuIjztQ,depth=10,body=Historical 98 (batch=0),prevs=['$D9gUbM3vrg7KAVDrXowcP0jmzjX_VM2OHArxGZy6wc8']",
  "event_id=$D9gUbM3vrg7KAVDrXowcP0jmzjX_VM2OHArxGZy6wc8,depth=10,body=Historical 97 (batch=0),prevs=['$fUs553QBZQ-3MqELA3X6pmCL6F9HsEGc0eAyIQ5w-KQ']",
  "event_id=$fUs553QBZQ-3MqELA3X6pmCL6F9HsEGc0eAyIQ5w-KQ,depth=10,body=Historical 96 (batch=0),prevs=['$Txz5IQUjGCf1ewtLvxmPKS0MrGD2LYoh6JwoQcXPYYI']",
  "event_id=$Txz5IQUjGCf1ewtLvxmPKS0MrGD2LYoh6JwoQcXPYYI,depth=10,body=Historical 95 (batch=0),prevs=['$kC7jJEVaeGxRbaGAECrje-j_rUWodeKtXT5TByOR3_0']",
  "event_id=$kC7jJEVaeGxRbaGAECrje-j_rUWodeKtXT5TByOR3_0,depth=10,body=Historical 94 (batch=0),prevs=['$qQ_Qw4R3XJ65ftHFvt7WyUg1-TrJ5ubgw4ln93O3qSE']",
  "event_id=$qQ_Qw4R3XJ65ftHFvt7WyUg1-TrJ5ubgw4ln93O3qSE,depth=10,body=Historical 93 (batch=0),prevs=['$z6Sohu4b39SVOiprB26Ke9XNo1EWuzZysQ-jyc80oXs']",
  "event_id=$z6Sohu4b39SVOiprB26Ke9XNo1EWuzZysQ-jyc80oXs,depth=10,body=Historical 92 (batch=0),prevs=['$CP4JNyEaRikkHIC-1OpoXhw3y3s_0_s-rqnKu_63aFg']",
  "event_id=$CP4JNyEaRikkHIC-1OpoXhw3y3s_0_s-rqnKu_63aFg,depth=10,body=Historical 91 (batch=0),prevs=['$nCjxeXj_OF05JtxM8YUdUlx_moibUUy6QrosWt8R_Us']",
  "event_id=$nCjxeXj_OF05JtxM8YUdUlx_moibUUy6QrosWt8R_Us,depth=10,body=Historical 90 (batch=0),prevs=['$8sFfCVGCb97FXd1etQLR70vmJDjk6RNsgbo5ughLXl8']",
  "event_id=$8sFfCVGCb97FXd1etQLR70vmJDjk6RNsgbo5ughLXl8,depth=10,body=Historical 89 (batch=0),prevs=['$45AU3xVc6xF4qfrdJMh68kZIc-PF9hqkFmuOoxA_j08']",
  "event_id=$45AU3xVc6xF4qfrdJMh68kZIc-PF9hqkFmuOoxA_j08,depth=10,body=Historical 88 (batch=0),prevs=['$9JhvBwk32ygq52H9mKPryUxX3ildrK47p8bAECnMkcI']",
  "event_id=$9JhvBwk32ygq52H9mKPryUxX3ildrK47p8bAECnMkcI,depth=10,body=Historical 87 (batch=0),prevs=['$rXBGwIxCzRUCCQpNvMNiePqrKk6daAOb5nN2AuACDcg']",
  "event_id=$rXBGwIxCzRUCCQpNvMNiePqrKk6daAOb5nN2AuACDcg,depth=10,body=Historical 86 (batch=0),prevs=['$Iebf12p8JQRuVHfWIgVwyc8cqDkPwTvod2HJIAfaaXY']",
  "event_id=$Iebf12p8JQRuVHfWIgVwyc8cqDkPwTvod2HJIAfaaXY,depth=10,body=Historical 85 (batch=0),prevs=['$8CV6t9Yg5RrYzy1-t72ez47xVAgc45iM_nBcEr0r5u8']",
  "event_id=$8CV6t9Yg5RrYzy1-t72ez47xVAgc45iM_nBcEr0r5u8,depth=10,body=Historical 84 (batch=0),prevs=['$jF0yFS-VkCntnui9esPytzncMQ4vbpoI4dEtbnqm2zM']",
  "event_id=$jF0yFS-VkCntnui9esPytzncMQ4vbpoI4dEtbnqm2zM,depth=10,body=Historical 83 (batch=0),prevs=['$rEfXGwUAl6BfF0t_PtOoqnyiC02ACeOKB9zrWaB2k9w']",
  "event_id=$rEfXGwUAl6BfF0t_PtOoqnyiC02ACeOKB9zrWaB2k9w,depth=10,body=Historical 82 (batch=0),prevs=['$7sjkdcEQOMDA7bXvNadBsscUPsvgwHgF7lHq6qT5SCQ']",
  "event_id=$7sjkdcEQOMDA7bXvNadBsscUPsvgwHgF7lHq6qT5SCQ,depth=10,body=Historical 81 (batch=0),prevs=['$Ee4Zn_bD2_qgutvjVpmTLduivzstgTmaXoG4QYsk9kI']",
  "event_id=$Ee4Zn_bD2_qgutvjVpmTLduivzstgTmaXoG4QYsk9kI,depth=10,body=Historical 80 (batch=0),prevs=['$O1NfL_xO7qhf9XtZfwYPQJHRTgcP9UJZ_CU6UfnyTmI']",
  "event_id=$O1NfL_xO7qhf9XtZfwYPQJHRTgcP9UJZ_CU6UfnyTmI,depth=10,body=Historical 79 (batch=0),prevs=['$lSviYdCQKQye2QgoDaj7Ax1uKSp55bvUlS_Ax7vocPA']",
  "event_id=$lSviYdCQKQye2QgoDaj7Ax1uKSp55bvUlS_Ax7vocPA,depth=10,body=Historical 78 (batch=0),prevs=['$ES3Mz4RnN5yj2mv6HIloRnAQlryyAToscQP_74X0R3E']",
  "event_id=$ES3Mz4RnN5yj2mv6HIloRnAQlryyAToscQP_74X0R3E,depth=10,body=Historical 77 (batch=0),prevs=['$G6S-j3AT0tMMHoTXDRYJYGHmVSpy3I7qMPJp71PvqsE']",
  "event_id=$G6S-j3AT0tMMHoTXDRYJYGHmVSpy3I7qMPJp71PvqsE,depth=10,body=Historical 76 (batch=0),prevs=['$n2IZJ9fG-t9cVol8slIDErGnNdbPeacvAWCDlTGYpJk']",
  "event_id=$n2IZJ9fG-t9cVol8slIDErGnNdbPeacvAWCDlTGYpJk,depth=10,body=Historical 75 (batch=0),prevs=['$WxYHgWQRH2CKo5fXTiwH5zMrc7xuI3nsiBgDDSFFBbY']",
  "event_id=$WxYHgWQRH2CKo5fXTiwH5zMrc7xuI3nsiBgDDSFFBbY,depth=10,body=Historical 74 (batch=0),prevs=['$4SxomALNe4fQrzh990LW2MVe2hAh41hefUN96WklLwA']",
  "event_id=$4SxomALNe4fQrzh990LW2MVe2hAh41hefUN96WklLwA,depth=10,body=Historical 73 (batch=0),prevs=['$7jcugB1rv_Jp4wntQhdW_LrwAHjV4flw_uZ3A0rrKVY']",
  "event_id=$7jcugB1rv_Jp4wntQhdW_LrwAHjV4flw_uZ3A0rrKVY,depth=10,body=Historical 72 (batch=0),prevs=['$0JOxrvf7ZArMCYzB1qSz76-akAdDtf0B-ferG4uI3vo']",
  "event_id=$0JOxrvf7ZArMCYzB1qSz76-akAdDtf0B-ferG4uI3vo,depth=10,body=Historical 71 (batch=0),prevs=['$Vd0nksOUDQ92s-Kkn37Zhhj204cAUynybHuHrgtROTs']",
  "event_id=$Vd0nksOUDQ92s-Kkn37Zhhj204cAUynybHuHrgtROTs,depth=10,body=Historical 70 (batch=0),prevs=['$CCDHZGKctXGPB5bAoEbrNk7cXCUiDtIL7PJ1VQGwIS0']",
  "event_id=$CCDHZGKctXGPB5bAoEbrNk7cXCUiDtIL7PJ1VQGwIS0,depth=10,body=Historical 69 (batch=0),prevs=['$3w0P2g8VdVb1ar52A_9XXeON3vmWb6sr_Lctjcyp11A']",
  "event_id=$3w0P2g8VdVb1ar52A_9XXeON3vmWb6sr_Lctjcyp11A,depth=10,body=Historical 68 (batch=0),prevs=['$-fRkdzIZbqczQ85DLuNk9l9DlYgtroT3Sj2hY4PjK3Y']",
  "event_id=$-fRkdzIZbqczQ85DLuNk9l9DlYgtroT3Sj2hY4PjK3Y,depth=10,body=Historical 67 (batch=0),prevs=['$jX0KrPhWbDIHoxsFZCKm8VJLiRaz7zbFLRpcPmXrNLU']",
  "event_id=$jX0KrPhWbDIHoxsFZCKm8VJLiRaz7zbFLRpcPmXrNLU,depth=10,body=Historical 66 (batch=0),prevs=['$RZaiBaIb5pXeFu21n3o8agvfPOzYPHZW2pg-NYnK2Wo']",
  "event_id=$RZaiBaIb5pXeFu21n3o8agvfPOzYPHZW2pg-NYnK2Wo,depth=10,body=Historical 65 (batch=0),prevs=['$Ayy7g5q4SVDDI2n4AjMKEhF7JKYekYoezs42uVlqKQo']",
  "event_id=$Ayy7g5q4SVDDI2n4AjMKEhF7JKYekYoezs42uVlqKQo,depth=10,body=Historical 64 (batch=0),prevs=['$Qrtts5rHLUrB3SH__uKCz9M_IzT8dwLEi5cZbL5XSrI']",
  "event_id=$Qrtts5rHLUrB3SH__uKCz9M_IzT8dwLEi5cZbL5XSrI,depth=10,body=Historical 63 (batch=0),prevs=['$GzpO60z90GafGhNpczoL9-_9sA4X9KAIx-oOp3Ak5fs']",
  "event_id=$GzpO60z90GafGhNpczoL9-_9sA4X9KAIx-oOp3Ak5fs,depth=10,body=Historical 62 (batch=0),prevs=['$FoDpnYsHjsEPKpk1aBTznOupi2Nq0pDcwgPup3EuwHY']",
  "event_id=$FoDpnYsHjsEPKpk1aBTznOupi2Nq0pDcwgPup3EuwHY,depth=10,body=Historical 61 (batch=0),prevs=['$x22YRSOcrA__Jj1jlAjUQj7_aDJxmzgXfn03nDgNuAs']",
  "event_id=$x22YRSOcrA__Jj1jlAjUQj7_aDJxmzgXfn03nDgNuAs,depth=10,body=Historical 60 (batch=0),prevs=['$3abKTbz8gCJ7WVGCAX4gdKKjctfq2UBwAq_kZAiMb6o']",
  "event_id=$3abKTbz8gCJ7WVGCAX4gdKKjctfq2UBwAq_kZAiMb6o,depth=10,body=Historical 59 (batch=0),prevs=['$6JgNxTembrNVYP3Ko6VgpHJNILIqIvTXwPpIsds63BA']",
  "event_id=$6JgNxTembrNVYP3Ko6VgpHJNILIqIvTXwPpIsds63BA,depth=10,body=Historical 58 (batch=0),prevs=['$NUENCAs9SSA4UUHind2mtrX_-5_H-GTXJ4DjQ8o0hVo']",
  "event_id=$NUENCAs9SSA4UUHind2mtrX_-5_H-GTXJ4DjQ8o0hVo,depth=10,body=Historical 57 (batch=0),prevs=['$c12ynew3nRtCewk7IvWy1EurV2XHgRh1sRbj9x5OwJA']",
  "event_id=$c12ynew3nRtCewk7IvWy1EurV2XHgRh1sRbj9x5OwJA,depth=10,body=Historical 56 (batch=0),prevs=['$xcqepPdOhubqAJ2xzBBZg0kuoPnfW4DcTJcj0UiRnDU']",
  "event_id=$xcqepPdOhubqAJ2xzBBZg0kuoPnfW4DcTJcj0UiRnDU,depth=10,body=Historical 55 (batch=0),prevs=['$BPlbbeAqGAzwTsSA-B0qOOYkZyovhvESdtcANOsobdk']",
  "event_id=$BPlbbeAqGAzwTsSA-B0qOOYkZyovhvESdtcANOsobdk,depth=10,body=Historical 54 (batch=0),prevs=['$Z40RGtNNkb54tu_EjNyCc3TG3JAzDn2VNFKcogEpquo']",
  "event_id=$Z40RGtNNkb54tu_EjNyCc3TG3JAzDn2VNFKcogEpquo,depth=10,body=Historical 53 (batch=0),prevs=['$K-50fqiUNw5NkQeGMkg3fgaJCwA9bm5WtTM7AWmfbvw']",
  "event_id=$K-50fqiUNw5NkQeGMkg3fgaJCwA9bm5WtTM7AWmfbvw,depth=10,body=Historical 52 (batch=0),prevs=['$71c4Wa_ks9TcN4nwj0403YQGRRVj-6rhJkQlwoIiJf4']",
  "event_id=$71c4Wa_ks9TcN4nwj0403YQGRRVj-6rhJkQlwoIiJf4,depth=10,body=Historical 51 (batch=0),prevs=['$o16ueMl2wNS6UfeDDt1JJDP5GeHDAo3G-mZnc5kFVA8']",
  "event_id=$o16ueMl2wNS6UfeDDt1JJDP5GeHDAo3G-mZnc5kFVA8,depth=10,body=Historical 50 (batch=0),prevs=['$Tf7hucPlbAIsJSJC_SZTerIDhA601DVXdktkmuR5Kw8']",
  "event_id=$Tf7hucPlbAIsJSJC_SZTerIDhA601DVXdktkmuR5Kw8,depth=10,body=Historical 49 (batch=0),prevs=['$sCpJSEbWzgIZaVxLlGb_JkxhYFj2s16ZloJPiafivVs']",
  "event_id=$sCpJSEbWzgIZaVxLlGb_JkxhYFj2s16ZloJPiafivVs,depth=10,body=Historical 48 (batch=0),prevs=['$UrxtBrZ2WrXFjInPAO2dwVtoPwDQxDDQ49GoqT5v6mI']",
  "event_id=$UrxtBrZ2WrXFjInPAO2dwVtoPwDQxDDQ49GoqT5v6mI,depth=10,body=Historical 47 (batch=0),prevs=['$7PoOmq5lSm_3qEm2B5ggpuEqev14pFjMD-T_4BYqZYo']",
  "event_id=$7PoOmq5lSm_3qEm2B5ggpuEqev14pFjMD-T_4BYqZYo,depth=10,body=Historical 46 (batch=0),prevs=['$2DhrL57VVj1KJuWeIP1_UZHrD7VQq2AUksvMDiTPD-4']",
  "event_id=$2DhrL57VVj1KJuWeIP1_UZHrD7VQq2AUksvMDiTPD-4,depth=10,body=Historical 45 (batch=0),prevs=['$8JexHkPI8s_95LGsa-xS7IUA6pPAzl1Wu6HOkezX4hk']",
  "event_id=$8JexHkPI8s_95LGsa-xS7IUA6pPAzl1Wu6HOkezX4hk,depth=10,body=Historical 44 (batch=0),prevs=['$D1BSCRk1kps83i5-Tm34uZGwTCCxNlmPt-QrVzJ3gKQ']",
  "event_id=$D1BSCRk1kps83i5-Tm34uZGwTCCxNlmPt-QrVzJ3gKQ,depth=10,body=Historical 43 (batch=0),prevs=['$2sdel6OjRf9AArfA-Lp-6AxAXMEGvus5j9CupJmPfpk']",
  "event_id=$2sdel6OjRf9AArfA-Lp-6AxAXMEGvus5j9CupJmPfpk,depth=10,body=Historical 42 (batch=0),prevs=['$ts6IiQMG8YyMwDYVUdRplhzpJLQPuzZXE8TIjTm5Qtw']",
  "event_id=$ts6IiQMG8YyMwDYVUdRplhzpJLQPuzZXE8TIjTm5Qtw,depth=10,body=Historical 41 (batch=0),prevs=['$SxPDbdJ_VYhfcIkJe4sUCvZG71gnhDjgne-WM-gOncQ']",
  "event_id=$SxPDbdJ_VYhfcIkJe4sUCvZG71gnhDjgne-WM-gOncQ,depth=10,body=Historical 40 (batch=0),prevs=['$AOpiIZHC5mhpwV1RPzQd_29KHsY-niX0uuL3ofWoTyY']",
  "event_id=$AOpiIZHC5mhpwV1RPzQd_29KHsY-niX0uuL3ofWoTyY,depth=10,body=Historical 39 (batch=0),prevs=['$8vAjOM6qlvKS9JJAXQx4CCOqRSzMP6C9YlNi0ft1Y68']",
  "event_id=$8vAjOM6qlvKS9JJAXQx4CCOqRSzMP6C9YlNi0ft1Y68,depth=10,body=Historical 38 (batch=0),prevs=['$EUgYbcq2DMNLgzY7SaPtpNQAOKKYLKYIoGfNYQb8Y2A']",
  "event_id=$EUgYbcq2DMNLgzY7SaPtpNQAOKKYLKYIoGfNYQb8Y2A,depth=10,body=Historical 37 (batch=0),prevs=['$ibThSro6ruPZeNqjf_9UGXfo1kErnQUcRZTDAunDM-4']",
  "event_id=$ibThSro6ruPZeNqjf_9UGXfo1kErnQUcRZTDAunDM-4,depth=10,body=Historical 36 (batch=0),prevs=['$YcrZi3aSgm17cZUkGZf-MaR8EWzl-RdDf5qYctmnZ1k']",
  "event_id=$YcrZi3aSgm17cZUkGZf-MaR8EWzl-RdDf5qYctmnZ1k,depth=10,body=Historical 35 (batch=0),prevs=['$0BhcUb0o0wtIE4hwVqAs0AC591TPOx54idyv6TCTiEo']",
  "event_id=$0BhcUb0o0wtIE4hwVqAs0AC591TPOx54idyv6TCTiEo,depth=10,body=Historical 34 (batch=0),prevs=['$umgo6IT00-E22uIRr_e4AsclGtanloy1Aw5GzNpBNfc']",
  "event_id=$umgo6IT00-E22uIRr_e4AsclGtanloy1Aw5GzNpBNfc,depth=10,body=Historical 33 (batch=0),prevs=['$aka96B_0Yx9AljoQKr4QitStKb0RkcPucvFKusGdySc']",
  "event_id=$aka96B_0Yx9AljoQKr4QitStKb0RkcPucvFKusGdySc,depth=10,body=Historical 32 (batch=0),prevs=['$OJJa17fRud2uJLkJ0-mF8iQFsAvimrY_efopy6ctqTg']",
  "event_id=$OJJa17fRud2uJLkJ0-mF8iQFsAvimrY_efopy6ctqTg,depth=10,body=Historical 31 (batch=0),prevs=['$pLWU_gcJnZGRmruRUcPIqWcjBJ9zmh1lb2jv39RDipc']",
  "event_id=$pLWU_gcJnZGRmruRUcPIqWcjBJ9zmh1lb2jv39RDipc,depth=10,body=Historical 30 (batch=0),prevs=['$G-kuDTfZY1V23CzLgSXfgdctIvbxmnT0Nx-qUuUhGbw']",
  "event_id=$G-kuDTfZY1V23CzLgSXfgdctIvbxmnT0Nx-qUuUhGbw,depth=10,body=Historical 29 (batch=0),prevs=['$b5NQ52jYrGKU7-5lJojXF3xAyWcANt3P6CJ1_Mpw9hA']",
  "event_id=$b5NQ52jYrGKU7-5lJojXF3xAyWcANt3P6CJ1_Mpw9hA,depth=10,body=Historical 28 (batch=0),prevs=['$4oJCt-e8AZYL8WJuY_uV2COvrCzbTvC7RB8xAvxGvEA']",
  "event_id=$4oJCt-e8AZYL8WJuY_uV2COvrCzbTvC7RB8xAvxGvEA,depth=10,body=Historical 27 (batch=0),prevs=['$lP0kCgxZMRAQL6_zg0JLNvdn1lRf1dLWXaWMa4ZT5Iw']",
  "event_id=$lP0kCgxZMRAQL6_zg0JLNvdn1lRf1dLWXaWMa4ZT5Iw,depth=10,body=Historical 26 (batch=0),prevs=['$b46KcYyRVIQJ2Mf6lc7UC56ViSxV9h43SVeQ5gYQ0MU']",
  "event_id=$b46KcYyRVIQJ2Mf6lc7UC56ViSxV9h43SVeQ5gYQ0MU,depth=10,body=Historical 25 (batch=0),prevs=['$b35VNurzabrSP0KvVCXRB1i-FjbDS8Ly-UZcU5m9RC0']",
  "event_id=$b35VNurzabrSP0KvVCXRB1i-FjbDS8Ly-UZcU5m9RC0,depth=10,body=Historical 24 (batch=0),prevs=['$8b1w7cxe5bdMj9mKrZTD32szDIVDZutWo1iXUsEQBSM']",
  "event_id=$8b1w7cxe5bdMj9mKrZTD32szDIVDZutWo1iXUsEQBSM,depth=10,body=Historical 23 (batch=0),prevs=['$vqlAlL8FDxucbRlZISrTtvtP4G1tSHNzbZwWEzAMbRM']",
  "event_id=$vqlAlL8FDxucbRlZISrTtvtP4G1tSHNzbZwWEzAMbRM,depth=10,body=Historical 22 (batch=0),prevs=['$ACWiMQWRjseJTFI_4yFLcrr-U7qzeHeSJpOlWOm7H2c']",
  "event_id=$ACWiMQWRjseJTFI_4yFLcrr-U7qzeHeSJpOlWOm7H2c,depth=10,body=Historical 21 (batch=0),prevs=['$mkKg3O1vyzZXCJoN0xEDuZYcm-mra3neT8peKSaI-fQ']",
  "event_id=$mkKg3O1vyzZXCJoN0xEDuZYcm-mra3neT8peKSaI-fQ,depth=10,body=Historical 20 (batch=0),prevs=['$Aro7lP7i_onbj9g5-tgTxKR7Xwo2u6H9xMKVb0Q4OQo']",
  "event_id=$Aro7lP7i_onbj9g5-tgTxKR7Xwo2u6H9xMKVb0Q4OQo,depth=10,body=Historical 19 (batch=0),prevs=['$ZT0davtwy-6ltpLlA7xCRDoZTbBKrFEm0xywwBqmI74']",
  "event_id=$ZT0davtwy-6ltpLlA7xCRDoZTbBKrFEm0xywwBqmI74,depth=10,body=Historical 18 (batch=0),prevs=['$LYfu_QQSdd9Murplu_qT56yJXtXNF0PIfJ-4-zj_OK4']",
  "event_id=$LYfu_QQSdd9Murplu_qT56yJXtXNF0PIfJ-4-zj_OK4,depth=10,body=Historical 17 (batch=0),prevs=['$sCjd4Lz7kNCDqKnV4NpyEbxufPa5ygfhMIXD5tvZIVE']",
  "event_id=$sCjd4Lz7kNCDqKnV4NpyEbxufPa5ygfhMIXD5tvZIVE,depth=10,body=Historical 16 (batch=0),prevs=['$7b8cgWaAtDefi5UR74eFaIq-OCAozn1z-095TfJYYWc']",
  "event_id=$7b8cgWaAtDefi5UR74eFaIq-OCAozn1z-095TfJYYWc,depth=10,body=Historical 15 (batch=0),prevs=['$DJ4LuxKnd1pjfsvyqbx5lWFucWgHi-ouH1GoS_8MQXs']",
  "event_id=$DJ4LuxKnd1pjfsvyqbx5lWFucWgHi-ouH1GoS_8MQXs,depth=10,body=Historical 14 (batch=0),prevs=['$GeABTSXvlqx9Ul4j4vQHQ0xHiZqKjRvZbXQQjPpBQZA']",
  "event_id=$GeABTSXvlqx9Ul4j4vQHQ0xHiZqKjRvZbXQQjPpBQZA,depth=10,body=Historical 13 (batch=0),prevs=['$KoqVyBic8-LUcPwfk3cN-xgwPvcHmPL8kUrVCVXl6Q8']",
  "event_id=$KoqVyBic8-LUcPwfk3cN-xgwPvcHmPL8kUrVCVXl6Q8,depth=10,body=Historical 12 (batch=0),prevs=['$Rn3edaeQ2P7DiyOh5y2_dtPK_sg_97neVHHDXCaga0g']",
  "event_id=$Rn3edaeQ2P7DiyOh5y2_dtPK_sg_97neVHHDXCaga0g,depth=10,body=Historical 11 (batch=0),prevs=['$rRXAVfkswED2m4zGvzd3E3msFjbN1RjP08DblJb9kbY']",
  "event_id=$rRXAVfkswED2m4zGvzd3E3msFjbN1RjP08DblJb9kbY,depth=10,body=Historical 10 (batch=0),prevs=['$7NE5L9LaMSqUj2gwxB46vZrCIDKklNRJNEnYhhluC3I']",
  "event_id=$7NE5L9LaMSqUj2gwxB46vZrCIDKklNRJNEnYhhluC3I,depth=10,body=Historical 9 (batch=0),prevs=['$Legp3Fec3qa5Matct10VzlsNU-cCYSfOMpEC1wWRCSw']",
  "event_id=$Legp3Fec3qa5Matct10VzlsNU-cCYSfOMpEC1wWRCSw,depth=10,body=Historical 8 (batch=0),prevs=['$Ot4kjqVOhGVkEWIshCwP9AmsHX9Dw_OG_rAfzF2YYgk']",
  "event_id=$Ot4kjqVOhGVkEWIshCwP9AmsHX9Dw_OG_rAfzF2YYgk,depth=10,body=Historical 7 (batch=0),prevs=['$_NgCYX2d-zby256Pt84Aw4WOtYtH5kaG9Qq5nrSISFo']",
  "event_id=$_NgCYX2d-zby256Pt84Aw4WOtYtH5kaG9Qq5nrSISFo,depth=10,body=Historical 6 (batch=0),prevs=['$wm5gnTie-UwOxwYVM6YYI6qbOO9g_n-IZ900ouJf4yI']",
  "event_id=$wm5gnTie-UwOxwYVM6YYI6qbOO9g_n-IZ900ouJf4yI,depth=10,body=Historical 5 (batch=0),prevs=['$d8O1CwNO3PfEYgODGj_6eHdxs-8H0Nk3UaoBnrJ8QBs']",
  "event_id=$rFNqVLF37MMcg7Dy8DjxnpUIyo8q-GBEs35AHKJRe8c,depth=11,body=Message 1 (eventIDsAfter),prevs=['$-VN0Wx6nnEzZLwFeON19jL9hW07xo1rGS08HsmBtA2g']",
  "event_id=$-VN0Wx6nnEzZLwFeON19jL9hW07xo1rGS08HsmBtA2g,depth=10,body=Message 0 (eventIDsAfter),prevs=['$n9kq5qDGfNxKw7_Cb8kIC-9BrQ0Kg_sTWn9_nLwovA4']",
  "event_id=$n9kq5qDGfNxKw7_Cb8kIC-9BrQ0Kg_sTWn9_nLwovA4,depth=9,body=Message 1 (eventIDsBefore),prevs=['$JdciLNIztkJyL8kE0GAs_JNRKx00ZYkfkT0Hw9bZmTY']"
]
```
This commit is contained in:
Eric Eastwood 2021-10-29 14:10:43 -05:00
parent 3d387f94fc
commit fb8e2814f1

View file

@ -648,6 +648,98 @@ class FederationEventHandler:
logger.info("Got %d prev_events", len(missing_events))
await self._process_pulled_events(origin, missing_events, backfilled=False)
async def generateEventIdGraphFromEvents(
self, events: Iterable[EventBase]
) -> Dict[str, Iterable[str]]:
event_map = {event.event_id: event for event in events}
# Since the insertion event we try to reference later on might be in the
# backfill chunk itself, we need to make it easy to lookup. Maps a given
# batch_id to the insertion event.
batch_id_map = {
event.content.get(
EventContentFields.MSC2716_NEXT_BATCH_ID, None
): event.event_id
for event in events
if event.type == EventTypes.MSC2716_INSERTION
}
# Map a given event to it's successors (backwards prev_events)
successor_event_id_map = {}
for event in events:
for prev_event_id in event.prev_event_ids():
successor_event_id_map.setdefault(prev_event_id, []).append(
event.event_id
)
event_id_graph = {}
for event in events:
# Assign the real edges to the graph.
# Make a copy so we don't modify the actual prev_events when we extend them below.
event_id_graph.setdefault(event.event_id, []).extend(
event.prev_event_ids().copy()
)
# We need to make some fake edge connections from the batch event at
# the bottom of the historical batch to the insertion event. This
# way the historical batch topologically sorts in ahead-in-time of
# the event we branched off of.
batch_id = event.content.get(EventContentFields.MSC2716_BATCH_ID, None)
if event.type == EventTypes.MSC2716_BATCH and batch_id:
# Maybe we can get lucky and save ourselves a lookup
# by checking the events in the backfill first
insertion_event_id = batch_id_map[
batch_id
] or await self._store.get_insertion_event_id_by_batch_id(
event.room_id, batch_id
)
if insertion_event_id:
# Connect the insertion event via a fake edge pointing to the
# batch event so the historical batch topologically sorts
# behind-in-time the insertion event.
event_id_graph.setdefault(insertion_event_id, []).append(
event.event_id
)
# Maybe we can get lucky and save ourselves a lookup
# by checking the events in the backfill first
insertion_event = event_map[
insertion_event_id
] or await self._store.get_event(
insertion_event_id, allow_none=True
)
if insertion_event:
# Connect the insertion events' `prev_event` successors
# via fake edges pointing to the insertion event itself
# so the insertion event sorts topologically
# behind-in-time the successor. Nestled perfectly
# between the prev_event and the successor.
for insertion_prev_event_id in insertion_event.prev_event_ids():
successor_event_ids = successor_event_id_map[
insertion_prev_event_id
]
logger.info(
"insertion_event_id=%s successor_event_ids=%s",
insertion_event_id,
successor_event_ids,
)
if successor_event_ids:
for successor_event_id in successor_event_ids:
# Don't add itself back as a successor
if successor_event_id != insertion_event_id:
# Fake edge to point the successor back
# at the insertion event
event_id_graph.setdefault(
successor_event_id, []
).append(insertion_event_id)
# TODO: We also need to add fake edges to connect the oldest-in-time messages
# in the batch to the event we branched off of, see https://github.com/matrix-org/synapse/pull/11114#discussion_r739300985
return event_id_graph
async def _process_pulled_events(
self, origin: str, events: Iterable[EventBase], backfilled: bool
) -> None:
@ -683,95 +775,12 @@ class FederationEventHandler:
# tell clients about them in order.
# sorted_events = sorted(events, key=lambda x: x.depth)
event_ids = [event.event_id for event in events]
event_map = {event.event_id: event for event in events}
# Since the insertion event we try to reference later on might be in the
# backfill chunk itself, we need to make it easy to lookup. Maps a given
# batch_id to the insertion event.
batch_id_map = {
event.content.get(
EventContentFields.MSC2716_NEXT_BATCH_ID, None
): event.event_id
for event in events
if event.type == EventTypes.MSC2716_INSERTION
}
successor_event_id_map = {}
for event in events:
for prev_event_id in event.prev_event_ids():
successor_event_id_map.setdefault(prev_event_id, []).append(
event.event_id
)
event_id_graph = {}
for event in events:
# Assign the real edges to the graph.
# Make a copy so we don't modify the actual prev_events when we extend them below.
event_id_graph.setdefault(event.event_id, []).extend(
event.prev_event_ids().copy()
)
# We need to make some fake edge connections from the batch event at
# the bottom of the historical batch to the insertion event. This
# way the historical batch topologically sorts in ahead-in-time of
# the event we branched off of.
batch_id = event.content.get(EventContentFields.MSC2716_BATCH_ID, None)
if event.type == EventTypes.MSC2716_BATCH and batch_id:
# Maybe we can get lucky and save ourselves a lookup
# by checking the events in the backfill first
insertion_event_id = batch_id_map[
batch_id
] or await self._store.get_insertion_event_id_by_batch_id(
event.room_id, batch_id
)
if insertion_event_id:
# Add the insertion event as a fake edge connection to the batch
# event so the historical batch topologically sorts below
# the "live" event we branched off of.
event_id_graph.setdefault(event.event_id, []).append(
insertion_event_id
)
# Maybe we can get lucky and save ourselves a lookup
# by checking the events in the backfill first
insertion_event = event_map[
insertion_event_id
] or await self._store.get_event(
insertion_event_id, allow_none=True
)
if insertion_event:
# Also add some fake edges to connect the insertion
# event to it's prev_event successors so it sorts
# topologically behind-in-time the successor. Nestled
# perfectly between the prev_event and the successor.
for insertion_prev_event_id in insertion_event.prev_event_ids():
successor_event_ids = successor_event_id_map[
insertion_prev_event_id
]
logger.info(
"insertion_event_id=%s successor_event_ids=%s",
insertion_event_id,
successor_event_ids,
)
if successor_event_ids:
event_id_graph.setdefault(
insertion_event_id, []
).extend(
[
successor_event_id
for successor_event_id in successor_event_ids
# Don't add itself back as a successor
if successor_event_id != insertion_event_id
]
)
# We want to sort topologically so we process them and tell clients
# about them in order.
sorted_events = []
event_ids = [event.event_id for event in events]
event_map = {event.event_id: event for event in events}
event_id_graph = await self.generateEventIdGraphFromEvents(events)
for event_id in sorted_topologically(event_ids, event_id_graph):
sorted_events.append(event_map[event_id])
sorted_events = reversed(sorted_events)