Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
POD
Commits
a8c51bde
Unverified
Commit
a8c51bde
authored
3 years ago
by
Vasili Novikov
Browse files
Options
Download
Email Patches
Plain Diff
Allow search in /bulk API
parent
549ce0a9
Pipeline
#2718
passed with stage
in 10 minutes and 40 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
docs/HTTP_API.md
+10
-7
docs/HTTP_API.md
src/api_model.rs
+2
-0
src/api_model.rs
src/internal_api.rs
+18
-4
src/internal_api.rs
src/warp_api.rs
+1
-1
src/warp_api.rs
src/warp_endpoints.rs
+1
-1
src/warp_endpoints.rs
with
32 additions
and
13 deletions
+32
-13
docs/HTTP_API.md
+
10
-
7
View file @
a8c51bde
...
...
@@ -278,25 +278,28 @@ without filtering.
### POST /v3/$owner_key/bulk
```
json
```
json
5
{
"auth": $auth_json,
"payload": {
"createItems": [
{
"id"
:
"something-12345"
,
"type"
:
"Person"
,
...
},
{ "id": "something-12345", "type": "Person",
/* ... */
},
{}, // same structure as create_item endpoint above
...
//
...
],
"updateItems": [
{
"id"
:
"something-67899"
,
...
},
{ "id": "something-67899",
/* ... */
},
{}, // same structure as update_item endpoint above
...
//
...
],
"deleteItems"
:
[
"$id"
,
"$id"
,
"$id"
,
...
],
"deleteItems": [ "$id", "$id", "$id",
/* ... */
],
"createEdges": [
{}, // same structure as create_edge endpoint above
{},
...
// ...
],
"search": [
{ /* same structure as in /search API */ }
]
}
}
...
...
This diff is collapsed.
Click to expand it.
src/api_model.rs
+
2
-
0
View file @
a8c51bde
...
...
@@ -78,6 +78,8 @@ pub struct Bulk {
pub
delete_items
:
Vec
<
String
>
,
#[serde(default)]
pub
create_edges
:
Vec
<
CreateEdge
>
,
#[serde(default)]
pub
search
:
Vec
<
Search
>
,
}
#[derive(Serialize,
Deserialize,
Debug)]
...
...
This diff is collapsed.
Click to expand it.
src/internal_api.rs
+
18
-
4
View file @
a8c51bde
...
...
@@ -328,15 +328,17 @@ pub fn bulk_tx(
pod_owner
:
&
str
,
cli
:
&
CliOptions
,
database_key
:
&
DatabaseKey
,
)
->
Result
<
()
>
{
)
->
Result
<
Value
>
{
info!
(
"Performing bulk action with {} new items, {} updated items, {} deleted items"
,
bulk
.create_items
.len
(),
bulk
.update_items
.len
(),
bulk
.delete_items
.len
(),
);
let
mut
created_items
=
Vec
::
new
();
for
item
in
bulk
.create_items
{
create_item_tx
(
tx
,
schema
,
item
,
pod_owner
,
cli
,
database_key
)
?
;
let
id
=
create_item_tx
(
tx
,
schema
,
item
,
pod_owner
,
cli
,
database_key
)
?
;
created_items
.push
(
id
);
}
for
item
in
bulk
.update_items
{
update_item_tx
(
tx
,
schema
,
&
item
.id
,
item
.fields
)
?
;
...
...
@@ -344,10 +346,22 @@ pub fn bulk_tx(
for
item_id
in
bulk
.delete_items
{
delete_item_tx
(
tx
,
schema
,
&
item_id
)
?
;
}
let
mut
created_edges
=
Vec
::
new
();
for
item_id
in
bulk
.create_edges
{
create_edge
(
tx
,
item_id
)
?
;
let
id
=
create_edge
(
tx
,
item_id
)
?
;
created_edges
.push
(
id
);
}
Ok
(())
let
mut
search_results
=
Vec
::
new
();
for
query
in
bulk
.search
{
let
result
=
search
(
tx
,
schema
,
query
)
?
;
search_results
.push
(
result
);
}
let
result
=
serde_json
::
json!
({
"createItems"
:
created_items
,
"createEdges"
:
created_edges
,
"search"
:
search_results
,
});
Ok
(
result
)
}
fn
item_base_to_json
(
tx
:
&
Tx
,
item
:
ItemBase
,
schema
:
&
Schema
)
->
Result
<
Map
<
String
,
Value
>>
{
...
...
This diff is collapsed.
Click to expand it.
src/warp_api.rs
+
1
-
1
View file @
a8c51bde
...
...
@@ -124,7 +124,7 @@ pub async fn run_server(cli_options: CliOptions) {
.map
(
move
|
owner
:
String
,
body
:
PayloadWrapper
<
Bulk
>
|
{
let
cli
=
cli_options_arc_clone
.deref
();
let
result
=
warp_endpoints
::
bulk
(
owner
,
init_db
.deref
(),
body
,
cli
);
let
result
=
result
.map
(|
()
|
warp
::
reply
::
json
(
&
serde_json
::
json!
({})
));
let
result
=
result
.map
(|
value
|
warp
::
reply
::
json
(
&
value
));
respond_with_result
(
result
)
});
...
...
This diff is collapsed.
Click to expand it.
src/warp_endpoints.rs
+
1
-
1
View file @
a8c51bde
...
...
@@ -88,7 +88,7 @@ pub fn bulk(
init_db
:
&
RwLock
<
HashSet
<
String
>>
,
body
:
PayloadWrapper
<
Bulk
>
,
cli
:
&
CliOptions
,
)
->
Result
<
()
>
{
)
->
Result
<
Value
>
{
let
auth
=
body
.auth
;
let
payload
=
body
.payload
;
let
database_key
=
auth_to_database_key
(
auth
)
?
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets