MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / patchRoute

Method patchRoute

internal/server/handlers_items_patch.go:305–348  ·  view source on GitHub ↗

patchRoute is routeContentUpdate for a patch: the same settle. A room with a live writer gets the patch through a patch-capable applier tab (step 2); with no live writer the patch is computed in the store transaction (step 1).

(
	w http.ResponseWriter,
	r *http.Request,
	item *models.Item,
	input *models.ItemUpdate,
	precheck func(*sql.Tx, *models.Item) error,
	parentLink *store.ParentLinkUpdate,
	pruned *int,
	p *itemPatch,
)

Source from the content-addressed store, hash-verified

303// a live writer gets the patch through a patch-capable applier tab (step 2);
304// with no live writer the patch is computed in the store transaction (step 1).
305func (s *Server) patchRoute(
306 w http.ResponseWriter,
307 r *http.Request,
308 item *models.Item,
309 input *models.ItemUpdate,
310 precheck func(*sql.Tx, *models.Item) error,
311 parentLink *store.ParentLinkUpdate,
312 pruned *int,
313 p *itemPatch,
314) (contentRoute, *models.Item) {
315 var updated *models.Item
316 outcome, paErr := settleContentRoute(
317 r.Context(),
318 func() bool { return s.collab.HasElectableApplier(item.ID) },
319 func() error {
320 return s.collab.PruneAndApply(item.ID, func() error {
321 pc := composePruneWithPrecheck(s, item.ID, precheck, pruned)
322 u, uerr := s.store.UpdateItemWithParentLink(item.ID, fenceSeedsBefore(*input), pc, parentLink)
323 if uerr != nil {
324 return uerr
325 }
326 s.noteSeedBoundary(item.ID, u)
327 updated = u
328 return nil
329 })
330 },
331 applierSettleBudget, applierSettlePoll,
332 )
333 switch outcome {
334 case settleElectApplier:
335 return s.patchViaApplier(w, item, input, parentLink, p)
336 case settleDirectWrote:
337 return contentRouteDirectWrote, updated
338 case settleUnsettled:
339 writeRoomSettlingError(w, itemRefOrSlug(*item))
340 return contentRouteHandled, nil
341 default:
342 if s.writeTypedItemRefusal(w, item, paErr, input.ChatGPTDoor) {
343 return contentRouteHandled, nil
344 }
345 writeInternalError(w, paErr)
346 return contentRouteHandled, nil
347 }
348}
349
350// patchActivityMeta adds the patch's own keys to the update's activity
351// entry: its id, how many edits, and whether it rebased.

Callers 1

updateItemMethod · 0.95

Calls 12

noteSeedBoundaryMethod · 0.95
patchViaApplierMethod · 0.95
writeTypedItemRefusalMethod · 0.95
settleContentRouteFunction · 0.85
composePruneWithPrecheckFunction · 0.85
fenceSeedsBeforeFunction · 0.85
writeRoomSettlingErrorFunction · 0.85
itemRefOrSlugFunction · 0.85
writeInternalErrorFunction · 0.85
HasElectableApplierMethod · 0.80
PruneAndApplyMethod · 0.80

Tested by

no test coverage detected