Monorepo for Tangled tangled.org

appview/pulls: upload patches as blobs

By using blobs we massively increase our maximum patch size. When stored
directly on the record patches can be at most 2 MiB. By moving it to a
blob, we get a minimum of 50 MiB (smaller if the pds has set it but 50
is the default).

Signed-off-by: Samuel Shuert <me@thecoded.prof>
Signed-off-by: Seongmin Lee <git@boltless.me>

Changed files
+49 -37
appview
models
pulls
+1 -1
appview/models/pull.go
··· 83 83 Repo *Repo 84 84 } 85 85 86 + // NOTE: This method does not include patch blob in returned atproto record 86 87 func (p Pull) AsRecord() tangled.RepoPull { 87 88 var source *tangled.RepoPull_Source 88 89 if p.PullSource != nil { ··· 113 114 Repo: p.RepoAt.String(), 114 115 Branch: p.TargetBranch, 115 116 }, 116 - Patch: p.LatestPatch(), 117 117 Source: source, 118 118 } 119 119 return record
+48 -36
appview/pulls/pulls.go
··· 1240 1240 return 1241 1241 } 1242 1242 1243 + blob, err := comatproto.RepoUploadBlob(r.Context(), client, strings.NewReader(patch)) 1244 + if err != nil { 1245 + log.Println("failed to upload patch", err) 1246 + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 1247 + return 1248 + } 1249 + 1243 1250 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1244 1251 Collection: tangled.RepoPullNSID, 1245 1252 Repo: user.Did, ··· 1251 1258 Repo: string(repo.RepoAt()), 1252 1259 Branch: targetBranch, 1253 1260 }, 1254 - Patch: patch, 1261 + Patch: blob.Blob.Ref.String(), 1255 1262 Source: recordPullSource, 1256 1263 CreatedAt: time.Now().Format(time.RFC3339), 1257 1264 }, ··· 1327 1334 // apply all record creations at once 1328 1335 var writes []*comatproto.RepoApplyWrites_Input_Writes_Elem 1329 1336 for _, p := range stack { 1337 + blob, err := comatproto.RepoUploadBlob(r.Context(), client, strings.NewReader(p.LatestPatch())) 1338 + if err != nil { 1339 + log.Println("failed to upload patch blob", err) 1340 + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 1341 + return 1342 + } 1343 + 1330 1344 record := p.AsRecord() 1331 - write := comatproto.RepoApplyWrites_Input_Writes_Elem{ 1345 + record.Patch = blob.Blob.Ref.String() 1346 + writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 1332 1347 RepoApplyWrites_Create: &comatproto.RepoApplyWrites_Create{ 1333 1348 Collection: tangled.RepoPullNSID, 1334 1349 Rkey: &p.Rkey, ··· 1336 1351 Val: &record, 1337 1352 }, 1338 1353 }, 1339 - } 1340 - writes = append(writes, &write) 1354 + }) 1341 1355 } 1342 1356 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 1343 1357 Repo: user.Did, ··· 1862 1876 return 1863 1877 } 1864 1878 1865 - var recordPullSource *tangled.RepoPull_Source 1866 - if pull.IsBranchBased() { 1867 - recordPullSource = &tangled.RepoPull_Source{ 1868 - Branch: pull.PullSource.Branch, 1869 - Sha: sourceRev, 1870 - } 1879 + blob, err := comatproto.RepoUploadBlob(r.Context(), client, strings.NewReader(patch)) 1880 + if err != nil { 1881 + log.Println("failed to upload patch blob", err) 1882 + s.pages.Notice(w, "resubmit-error", "Failed to update pull request on the PDS. Try again later.") 1883 + return 1871 1884 } 1872 - if pull.IsForkBased() { 1873 - repoAt := pull.PullSource.RepoAt.String() 1874 - recordPullSource = &tangled.RepoPull_Source{ 1875 - Branch: pull.PullSource.Branch, 1876 - Repo: &repoAt, 1877 - Sha: sourceRev, 1878 - } 1879 - } 1885 + record := pull.AsRecord() 1886 + record.Patch = blob.Blob.Ref.String() 1887 + record.CreatedAt = time.Now().Format(time.RFC3339) 1880 1888 1881 1889 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1882 1890 Collection: tangled.RepoPullNSID, ··· 1884 1892 Rkey: pull.Rkey, 1885 1893 SwapRecord: ex.Cid, 1886 1894 Record: &lexutil.LexiconTypeDecoder{ 1887 - Val: &tangled.RepoPull{ 1888 - Title: pull.Title, 1889 - Target: &tangled.RepoPull_Target{ 1890 - Repo: string(repo.RepoAt()), 1891 - Branch: pull.TargetBranch, 1892 - }, 1893 - Patch: patch, // new patch 1894 - Source: recordPullSource, 1895 - CreatedAt: time.Now().Format(time.RFC3339), 1896 - }, 1895 + Val: &record, 1897 1896 }, 1898 1897 }) 1899 1898 if err != nil { ··· 1979 1978 } 1980 1979 defer tx.Rollback() 1981 1980 1981 + client, err := s.oauth.AuthorizedClient(r) 1982 + if err != nil { 1983 + log.Println("failed to authorize client") 1984 + s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.") 1985 + return 1986 + } 1987 + 1982 1988 // pds updates to make 1983 1989 var writes []*comatproto.RepoApplyWrites_Input_Writes_Elem 1984 1990 ··· 2012 2018 return 2013 2019 } 2014 2020 2021 + blob, err := comatproto.RepoUploadBlob(r.Context(), client, strings.NewReader(patch)) 2022 + if err != nil { 2023 + log.Println("failed to upload patch blob", err) 2024 + s.pages.Notice(w, "resubmit-error", "Failed to update pull request on the PDS. Try again later.") 2025 + return 2026 + } 2015 2027 record := p.AsRecord() 2028 + record.Patch = blob.Blob.Ref.String() 2016 2029 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 2017 2030 RepoApplyWrites_Create: &comatproto.RepoApplyWrites_Create{ 2018 2031 Collection: tangled.RepoPullNSID, ··· 2047 2060 return 2048 2061 } 2049 2062 2063 + blob, err := comatproto.RepoUploadBlob(r.Context(), client, strings.NewReader(patch)) 2064 + if err != nil { 2065 + log.Println("failed to upload patch blob", err) 2066 + s.pages.Notice(w, "resubmit-error", "Failed to update pull request on the PDS. Try again later.") 2067 + return 2068 + } 2050 2069 record := np.AsRecord() 2051 - 2070 + record.Patch = blob.Blob.Ref.String() 2052 2071 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 2053 2072 RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{ 2054 2073 Collection: tangled.RepoPullNSID, ··· 2082 2101 if err != nil { 2083 2102 log.Println("failed to resubmit pull", err) 2084 2103 s.pages.Notice(w, "pull-resubmit-error", "Failed to resubmit pull request. Try again later.") 2085 - return 2086 - } 2087 - 2088 - client, err := s.oauth.AuthorizedClient(r) 2089 - if err != nil { 2090 - log.Println("failed to authorize client") 2091 - s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.") 2092 2104 return 2093 2105 } 2094 2106