Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE-398 remove-many for bulk delete a bunch of rows by id (must be sam… #1938

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions desks/realm/app/bedrock.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
(edit:db +.act state bowl)
%remove
(remove:db +.act state bowl)
%remove-many
(remove-many:db +.act state bowl)

%relay
(relay:db +.act state bowl)
Expand Down
66 changes: 66 additions & 0 deletions desks/realm/lib/db.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,64 @@

[cards state]
::
++ remove-many :: only works on ids from same path
::bedrock &db-action [%remove-many %foo /example [[our ~2023.5.22..19.22.29..d0f7] [our ~2023.5.22..19.22.29..d0f7] ~]]
|= [[=type:common =path ids=(list id:common)] state=state-0 =bowl:gall]
~& %remove-many
^- (quip card state-0)

:: forward the request if we aren't the host
=/ path-row=path-row (~(got by paths.state) path)
?. =(host.path-row our.bowl)
=/ log2 (maybe-log hide-logs.state "{<src.bowl>} tried to have us ({<our.bowl>}) remove a row in {<path.path-row>} where we are not the host. forwarding the poke to the host: {<host.path-row>}")
:_ state
[%pass /dbpoke %agent [host.path-row dap.bowl] %poke %db-action !>([%remove-many type path ids])]~
:: permissions
=/ pt (~(got by tables.state) type)
=/ tbl (~(got by pt) path)
=/ index=@ud 0
=/ all-have-permission=?
|-
~& %permission-iter
?: =(index (lent ids))
%.y
=/ id (snag index ids)
=/ old-row (~(got by tbl) id) :: old row must first exist
?: (has-delete-permissions path-row old-row state bowl)
$(index +(index))
%.n
?. all-have-permission
=/ log1 (maybe-log hide-logs.state "{(scow %p src.bowl)} tried to delete a %{(scow %tas type)} row where they didn't have permissions")
`state

:: update path
=/ foreign-ship-sub-wire (weld /next/(scot %da updated-at.path-row) path)
=. updated-at.path-row now.bowl
=. received-at.path-row now.bowl
=. paths.state (~(put by paths.state) path path-row)

:: do the delete
=. index 0
=/ logs=(list db-row-del-change) ~
|-
?: =(index (lent ids))
~& logs
=. pt (~(put by pt) path tbl) :: update the pathed-table
=. tables.state (~(put by tables.state) type pt) :: update the tables.state
:: TODO remove remote-scry paths for the row

:: emit the change to subscribers
=/ cards=(list card) :~
:: tell subs about the new row
[%give %fact [/db (weld /path path) foreign-ship-sub-wire ~] db-changes+!>(logs)]
:: kick foreign ship subs to force them to re-sub for next update
[%give %kick [foreign-ship-sub-wire ~] ~]
==

[cards state]
=/ log=db-row-del-change [%del-row path type (snag index ids) (add now.bowl index)]
$(index +(index), tbl (~(del by tbl) (snag index ids)), del-log.state (~(put by del-log.state) (add now.bowl index) log), logs [log logs])
::
++ relay
:: supposed to be used by the sharer, poking their own ship,
:: regardless of if they are the host of either original or target path
Expand Down Expand Up @@ -1181,6 +1239,7 @@
[%create de-create-input-row]
[%edit (ot ~[[%id de-id] [%input-row de-input-row]])]
[%remove remove]
[%remove-many remove-many]
[%relay de-create-input-row]
==
::
Expand Down Expand Up @@ -1213,6 +1272,13 @@
[%id de-id]
==
::
++ remove-many
%- ot
:~ [%type (se %tas)]
[%path pa]
[%ids (ar de-id)]
==
::
++ de-create-from-space
%- ot
:~ [%path pa]
Expand Down
1 change: 1 addition & 0 deletions desks/realm/sur/db.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
[%create =req-id =input-row] :: sends %add-row to all subs
[%edit =id:common =input-row] :: sends %upd-row to all subs
[%remove =type:common =path =id:common] :: %host deleting the row, sends %delete to all peers
[%remove-many =type:common =path ids=(list id:common)] :: %host deleting the row, sends %delete to all peers
[%relay =req-id =input-row] :: like %create, but for creating a %relay (relay:common)
[%create-initial-spaces-paths ~]

Expand Down