Skip to content

Commit 69f0b00

Browse files
authored
Merge pull request #1990 from reebhub/PHP_Batch_Rev_Cnt
[PHP] Revisions & Counters pages batch [Replace C# samples]
2 parents 7df7c30 + a0dd6c6 commit 69f0b00

File tree

62 files changed

+7299
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7299
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Counters Batch Operation
2+
3+
*CounterBatchOperation* allows you to operate on multiple counters (`Increment`, `Get`, `Delete`) of different documents in a **single request**.
4+
5+
{PANEL: Syntax}
6+
7+
{CODE:php counter_batch_op@ClientApi\Operations\Counters\Counters.php /}
8+
9+
| Parameter | | |
10+
|------------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
11+
| **counterBatch** | `CounterBatch` | An object that holds a list of `DocumentCountersOperation`.<br>Each element in the list describes the counter operations to perform for a specific document |
12+
13+
{CODE:php counter_batch@ClientApi\Operations\Counters\Counters.php /}
14+
15+
#### DocumentCountersOperation
16+
17+
{CODE:php document_counters_op@ClientApi\Operations\Counters\Counters.php /}
18+
19+
#### CounterOperation
20+
21+
{CODE:php counter_operation@ClientApi\Operations\Counters\Counters.php /}
22+
23+
#### CounterOperationType
24+
25+
{CODE:php counter_operation_type@ClientApi\Operations\Counters\Counters.php /}
26+
27+
{INFO: Document updates as a result of a counter operation }
28+
A document that has counters holds all its counter names in the `metadata`.
29+
Therefore, when creating a new counter, the parent document is modified, as the counter's name needs to be added to the metadata.
30+
Deleting a counter also modifies the parent document, as the counter's name needs to be removed from the metadata.
31+
Incrementing an existing counter will not modify the parent document.
32+
33+
Even if a `DocumentCountersOperation` contains several `CounterOperation` items that affect the document's metadata (create, delete),
34+
the parent document will be modified **only once**, after all the `CounterOperation` items in this `DocumentCountersOperation` have been processed.
35+
If `DocumentCountersOperation` doesn't contain any `CounterOperation` that affects the metadata, the parent document won't be modified.
36+
37+
{INFO/}
38+
39+
{PANEL/}
40+
41+
{PANEL: Return Value}
42+
43+
* *CounterBatchOperation* returns a `CountersDetail` object, which holds a list of `CounterDetail` objects.
44+
45+
* If a `CounterOperationType` is `Increment` or `Get`, a `CounterDetail` object will be added to the result.
46+
`Delete` operations will not be included in the result.
47+
48+
{CODE:php counters_detail@ClientApi\Operations\Counters\Counters.php /}
49+
50+
{CODE:php counter_detail@ClientApi\Operations\Counters\Counters.php /}
51+
52+
{PANEL/}
53+
54+
{PANEL: Examples}
55+
56+
Assume we have two documents, `users/1` and `users/2`, that hold 3 counters each:
57+
`likes`, `dislikes` and `downloads` - with values 10, 20 and 30 (respectively)
58+
59+
---
60+
61+
### Example #1 : Increment Multiple Counters in a Batch
62+
63+
{CODE:php counter_batch_exmpl1@ClientApi\Operations\Counters\Counters.php /}
64+
65+
#### Result:
66+
{CODE-BLOCK:json}
67+
{
68+
"Counters":
69+
[
70+
{
71+
"DocumentId" : "users/1",
72+
"CounterName" : "likes",
73+
"TotalValue" : 15,
74+
"CounterValues" : null
75+
},
76+
{
77+
"DocumentId" : "users/1",
78+
"CounterName" : "dislikes",
79+
"TotalValue" : 20,
80+
"CounterValues" : null
81+
},
82+
{
83+
"DocumentId" : "users/2",
84+
"CounterName" : "likes",
85+
"TotalValue" : 110,
86+
"CounterValues" : null
87+
},
88+
{
89+
"DocumentId" : "users/2",
90+
"CounterName" : "score",
91+
"TotalValue" : 50,
92+
"CounterValues" : null
93+
}
94+
]
95+
}
96+
{CODE-BLOCK/}
97+
98+
---
99+
100+
### Example #2 : Get Multiple Counters in a Batch
101+
102+
{CODE:php counter_batch_exmpl2@ClientApi\Operations\Counters\Counters.php /}
103+
104+
#### Result:
105+
106+
{CODE-BLOCK:json}
107+
{
108+
"Counters":
109+
[
110+
{
111+
"DocumentId" : "users/1",
112+
"CounterName" : "likes",
113+
"TotalValue" : 15,
114+
"CounterValues" : null
115+
},
116+
{
117+
"DocumentId" : "users/1",
118+
"CounterName" : "downloads",
119+
"TotalValue" : 30,
120+
"CounterValues" : null
121+
},
122+
{
123+
"DocumentId" : "users/2",
124+
"CounterName" : "likes",
125+
"TotalValue" : 110,
126+
"CounterValues" : null
127+
},
128+
{
129+
"DocumentId" : "users/2",
130+
"CounterName" : "score",
131+
"TotalValue" : 50,
132+
"CounterValues" : null
133+
}
134+
]
135+
}
136+
{CODE-BLOCK/}
137+
138+
---
139+
140+
### Example #3 : Delete Multiple Counters in a Batch
141+
142+
{CODE:php counter_batch_exmpl3@ClientApi\Operations\Counters\Counters.php /}
143+
144+
#### Result:
145+
146+
{CODE-BLOCK:json}
147+
{
148+
"Counters": []
149+
}
150+
{CODE-BLOCK/}
151+
152+
---
153+
154+
### Example #4 : Mix Different Types of CounterOperations in a Batch
155+
156+
{CODE:php counter_batch_exmpl4@ClientApi\Operations\Counters\Counters.php /}
157+
158+
#### Result:
159+
160+
* Note: The `Delete` operations are Not included in the results.
161+
162+
{CODE-BLOCK:json}
163+
{
164+
"Counters":
165+
[
166+
{
167+
"DocumentId" : "users/1",
168+
"CounterName" : "likes",
169+
"TotalValue" : 30,
170+
"CounterValues" : null
171+
},
172+
null,
173+
{
174+
"DocumentId" : "users/2",
175+
"CounterName" : "likes",
176+
"TotalValue" : 110,
177+
"CounterValues" : null
178+
}
179+
]
180+
}
181+
{CODE-BLOCK/}
182+
183+
{PANEL/}
184+
185+
## Related Articles
186+
187+
### Operations
188+
189+
- [What are Operations](../../../client-api/operations/what-are-operations)
190+
- [Get Counters Operation](../../../client-api/operations/counters/get-counters)
191+
192+

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/counters/get-counters.dotnet.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It can be used to get the value of a single counter, multiple counters' values,
1717

1818
{INFO: }
1919

20-
__Return Full Results flag:__
20+
**Return Full Results flag:**
2121

2222
If RavenDB is running in a distributed cluster, and the database resides on several nodes,
2323
a counter can have a different *local* value on each database node, and the total counter value is the
@@ -63,8 +63,8 @@ The operation returns a `CountersDetail` object, which holds a list of `CounterD
6363

6464
{PANEL: Examples}
6565

66-
Assume we have a document "users/1" that holds 3 counters -
67-
_"likes"_, _"dislikes"_ and _"downloads"_ - with values 10, 20 and 30 (respectively)
66+
Assume we have a `users/1` document that holds 3 counters:
67+
`likes`, `dislikes` and `downloads` - with values 10, 20 and 30 (respectively)
6868

6969
### Example #1 : Get single counter
7070

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/counters/get-counters.java.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It can be used to get the value of a single counter, multiple counters' values,
1717

1818
{INFO: }
1919

20-
__Return Full Results flag__:
20+
**Return Full Results flag**:
2121

2222
If RavenDB is running in a distributed cluster, and the database resides on several nodes,
2323
a counter can have a different *local* value on each database node, and the total counter value is the
@@ -63,8 +63,8 @@ The operation returns a `CountersDetail` object, which holds a list of `CounterD
6363

6464
{PANEL: Examples}
6565

66-
Assume we have a document "users/1" that holds 3 counters -
67-
_"likes"_, _"dislikes"_ and _"downloads"_ - with values 10, 20 and 30 (respectively)
66+
Assume we have a `users/1` document that holds 3 counters:
67+
`likes`, `dislikes` and `downloads` - with values 10, 20 and 30 (respectively)
6868

6969
### Example #1 : Get single counter
7070

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/counters/get-counters.js.markdown

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ It can be used to get the value of a single counter, multiple counters' values,
1313

1414
| Parameter | Type | Description |
1515
|-----------------------|----------|-----------------------------------------------------------------------------------------------------------------------|
16-
| __docId__ | string | The ID of the document that holds the counters |
17-
| __counter__ | string | The name of the counter to get |
18-
| __counters__ | string[] | The list of counter names to get |
19-
| __returnFullResults__ | boolean | A flag which indicates if the operation should include a dictionary of counter values per database node in the result |
16+
| **docId** | string | The ID of the document that holds the counters |
17+
| **counter** | string | The name of the counter to get |
18+
| **counters** | string[] | The list of counter names to get |
19+
| **returnFullResults** | boolean | A flag which indicates if the operation should include a dictionary of counter values per database node in the result |
2020

2121
{INFO: }
2222

23-
__The full results flag:__
23+
**The full results flag:**
2424

2525
If RavenDB is running in a distributed cluster, and the database resides on several nodes,
2626
then a counter can have a different *local* value on each database node.
@@ -43,8 +43,8 @@ The operation returns a `CountersDetail` object, which holds a list of `CounterD
4343

4444
{PANEL: Examples}
4545

46-
Assume we have a document `users/1` that holds 3 counters -
47-
_"Likes"_, _"Dislikes"_ and _"Downloads"_ - with values 10, 20 and 30 (respectively)
46+
Assume we have a `users/1` document that holds 3 counters:
47+
`Likes`, `Dislikes` and `Downloads` - with values 10, 20 and 30 (respectively)
4848

4949
---
5050

0 commit comments

Comments
 (0)