mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Removing request chunking from NCN controller
This commit is contained in:
parent
42a5ccb96c
commit
c6cd8b8aaa
2 changed files with 24 additions and 48 deletions
|
@ -569,19 +569,13 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
protected function articleMarkReadMulti(array $url, array $data): Response {
|
||||
// determine whether to mark read or unread
|
||||
$set = ($url[1]=="read");
|
||||
// start a transaction and loop through the items
|
||||
$t = Arsse::$db->begin();
|
||||
$in = array_chunk($data['items'] ?? [], 50);
|
||||
for ($a = 0; $a < sizeof($in); $a++) {
|
||||
// initialize the matching context
|
||||
$c = new Context;
|
||||
$c->editions($in[$a]);
|
||||
try {
|
||||
Arsse::$db->articleMark(Arsse::$user->id, ['read' => $set], $c);
|
||||
} catch (ExceptionInput $e) {
|
||||
}
|
||||
// initialize the matching context
|
||||
$c = new Context;
|
||||
$c->editions($data['items'] ?? []);
|
||||
try {
|
||||
Arsse::$db->articleMark(Arsse::$user->id, ['read' => $set], $c);
|
||||
} catch (ExceptionInput $e) {
|
||||
}
|
||||
$t->commit();
|
||||
return new Response(204);
|
||||
}
|
||||
|
||||
|
@ -589,19 +583,13 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
protected function articleMarkStarredMulti(array $url, array $data): Response {
|
||||
// determine whether to mark starred or unstarred
|
||||
$set = ($url[1]=="star");
|
||||
// start a transaction and loop through the items
|
||||
$t = Arsse::$db->begin();
|
||||
$in = array_chunk(array_column($data['items'] ?? [], "guidHash"), 50);
|
||||
for ($a = 0; $a < sizeof($in); $a++) {
|
||||
// initialize the matching context
|
||||
$c = new Context;
|
||||
$c->articles($in[$a]);
|
||||
try {
|
||||
Arsse::$db->articleMark(Arsse::$user->id, ['starred' => $set], $c);
|
||||
} catch (ExceptionInput $e) {
|
||||
}
|
||||
// initialize the matching context
|
||||
$c = new Context;
|
||||
$c->articles(array_column($data['items'] ?? [], "guidHash"));
|
||||
try {
|
||||
Arsse::$db->articleMark(Arsse::$user->id, ['starred' => $set], $c);
|
||||
} catch (ExceptionInput $e) {
|
||||
}
|
||||
$t->commit();
|
||||
return new Response(204);
|
||||
}
|
||||
|
||||
|
|
|
@ -776,8 +776,6 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
$in = [
|
||||
["ook","eek","ack"],
|
||||
range(100, 199),
|
||||
range(100, 149),
|
||||
range(150, 199),
|
||||
];
|
||||
$inStar = $in;
|
||||
for ($a = 0; $a < sizeof($inStar); $a++) {
|
||||
|
@ -787,9 +785,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
}
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), $this->anything())->thenReturn(42);
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->editions([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->editions($in[1]))->thenThrow(new ExceptionInput("tooLong")); // data model function limited to 50 items for multiples
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->articles([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->articles($in[1]))->thenThrow(new ExceptionInput("tooLong")); // data model function limited to 50 items for multiples
|
||||
$exp = new Response(204);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/items/read/multiple")));
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/items/unread/multiple")));
|
||||
|
@ -812,27 +808,19 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/items/star/multiple", json_encode(['items' => $inStar[1]]), 'application/json')));
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/items/unstar/multiple", json_encode(['items' => $inStar[1]]), 'application/json')));
|
||||
// ensure the data model was queried appropriately for read/unread
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->articleMark(Arsse::$user->id, $read, (new Context)->editions([]));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[1]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[2]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[3]));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->articleMark(Arsse::$user->id, $unread, (new Context)->editions([]));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[1]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[2]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[3]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $read, (new Context)->editions([]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[1]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unread, (new Context)->editions([]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unread, (new Context)->editions($in[1]));
|
||||
// ensure the data model was queried appropriately for star/unstar
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $star, (new Context)->articles([]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[1]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[2]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[3]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->articles([]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[1]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[2]));
|
||||
Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[3]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $star, (new Context)->articles([]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $star, (new Context)->articles($in[1]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unstar, (new Context)->articles([]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[0]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $unstar, (new Context)->articles($in[1]));
|
||||
}
|
||||
|
||||
public function testQueryTheServerStatus() {
|
||||
|
|
Loading…
Reference in a new issue