Skip to content

Commit

Permalink
Merge branch 'release/4.1.19'
Browse files Browse the repository at this point in the history
* release/4.1.19:
  updated the changelog
  updated the changelog
  Apply fixes from StyleCI (#452)
  fixed the ViewThrottle middleware and added unit tests
  removed the tag eager loading on the post index route
  work
  • Loading branch information
austintoddj committed Apr 3, 2019
2 parents 97af11c + 541a14e commit 707bf7f
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 184 deletions.
29 changes: 20 additions & 9 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release Notes

## [v4.1.19](https://github.com/cnvs/canvas/compare/v4.1.18...v4.1.19)

### Changed
- Removed unnecessary eager loading from the post index route ([09d01c6](https://github.com/cnvs/canvas/commit/09d01c622f04997dc23ae64ac9719a067a28b734))

### Added
- Added unit tests for the ViewThrottle middleware ([087832e](https://github.com/cnvs/canvas/commit/087832eb6b7439dbe0f9214fea99020e9eaeed39))

### Fixed
- Refactored the ViewThrottle middleware to prune posts from the session instead of simply filtering ([087832e](https://github.com/cnvs/canvas/commit/087832eb6b7439dbe0f9214fea99020e9eaeed39))

## [v4.1.18](https://github.com/cnvs/canvas/compare/v4.1.17...v4.1.18)

### Changed
Expand All @@ -13,19 +24,19 @@

## [v4.1.16](https://github.com/cnvs/canvas/compare/v4.1.15...v4.1.16)

### Changed
- Updated the `Model::all()` usages to reduce the query sizes ([6655ecb](https://github.com/cnvs/canvas/commit/6655ecb78123e1a179c8514d85e02f9aa5d77c87), [0df1ba5](https://github.com/cnvs/canvas/commit/0df1ba52b8a972fcdc6d01f78c0af2c0a5c72c54))
- Refactored model attributes to use snake case ([d2f4784](https://github.com/cnvs/canvas/commit/d2f47840d75386f496ea9ff81a9baeb44841dd4c))
- Updated the Font Awesome library to 5.8 ([47af5b8](https://github.com/cnvs/canvas/commit/47af5b8bf11f3d62d7a189a6fc9bfb201a9fdac4))
- Updated the dark mode contrast ratios for increased readability ([a718b1b](https://github.com/cnvs/canvas/commit/a718b1bfa13223a9e73d233d336340978ea84f68))

### Added
- Added unit tests for the StoreViewData listener ([2e3aeb5](https://github.com/cnvs/canvas/commit/2e3aeb518aee9141fdec6485ca2c3844a7f98d24))
- Added unit tests for the Publish command ([637dd3f](https://github.com/cnvs/canvas/commit/637dd3fb2b1a1efd6a2c67fbeb77038737e8d725))

### Fixed
- Fixed the missing validation messages on Topics/Tags ([4d4231b](https://github.com/cnvs/canvas/commit/4d4231bd7da898e7ee28c38864944ede281cbb8d))

### Changed
- Updated the `Model::all()` usages to reduce the query sizes ([6655ecb](https://github.com/cnvs/canvas/commit/6655ecb78123e1a179c8514d85e02f9aa5d77c87), [0df1ba5](https://github.com/cnvs/canvas/commit/0df1ba52b8a972fcdc6d01f78c0af2c0a5c72c54))
- Refactored model attributes to use snake case ([d2f4784](https://github.com/cnvs/canvas/commit/d2f47840d75386f496ea9ff81a9baeb44841dd4c))
- Updated the Font Awesome library to 5.8 ([47af5b8](https://github.com/cnvs/canvas/commit/47af5b8bf11f3d62d7a189a6fc9bfb201a9fdac4))
- Updated the dark mode contrast ratios for increased readability ([a718b1b](https://github.com/cnvs/canvas/commit/a718b1bfa13223a9e73d233d336340978ea84f68))

## [v4.1.15](https://github.com/cnvs/canvas/compare/v4.1.14...v4.1.15)

### Added
Expand All @@ -39,10 +50,10 @@

## [v4.1.13](https://github.com/cnvs/canvas/compare/v4.1.12...v4.1.13)

### Added
- Added unit tests for the number suffix helper ([61d5b15](https://github.com/cnvs/canvas/commit/61d5b15eaee6bdf9571e5687cca9f80d4e309fe3))

### Changed
- Refactored the test suite to be more concise and accurate ([573b6e8](https://github.com/cnvs/canvas/commit/573b6e877933fc4e0d2ef46a0686650304b5a9f8))
- Refactored the migrations into a root `database` directory ([573b6e8](https://github.com/cnvs/canvas/commit/573b6e877933fc4e0d2ef46a0686650304b5a9f8))
- Updated the `.gitignore` ([a83978b](https://github.com/cnvs/canvas/commit/a83978b63fe2d1e4b25551cd9bf81a3f9ecbb908))

### Added
- Added unit tests for the number suffix helper ([61d5b15](https://github.com/cnvs/canvas/commit/61d5b15eaee6bdf9571e5687cca9f80d4e309fe3))
2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"/js/app.js": "/js/app.js?id=e14eab4148aca57fd14d",
"/css/app.css": "/css/app.css?id=30702a620a23ba741c32",
"/css/app-dark.css": "/css/app-dark.css?id=ceb9852370c32c15e835",
"/js/app.js.map": "/js/app.js.map?id=cac20b4e6af75f105d50",
"/js/app.js.map": "/js/app.js.map?id=b49f81db61bd83e7ae34",
"/favicon.png": "/favicon.png?id=d1ff042f5749eb7e2f66"
}
4 changes: 2 additions & 2 deletions resources/views/stats/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</p>
</div>
<div class="ml-auto">
<span class="text-muted">{{ sprintf('%s%s', $percentage, '%') }}</span>
<span class="text-muted">{{ sprintf('%s%%', $percentage) }}</span>
</div>
</div>
@endforeach
Expand All @@ -75,4 +75,4 @@
</div>
</div>
</div>
@endsection
@endsection
4 changes: 2 additions & 2 deletions src/Console/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function handle()
}

/**
* Create the directories for the views.
* Create the view directories.
*
* @return void
*/
Expand Down Expand Up @@ -104,7 +104,7 @@ protected function exportViews()
}

/**
* Compiles the HomeController stub.
* Compile the default controller stub.
*
* @return string
*/
Expand Down
18 changes: 9 additions & 9 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
class PostController extends Controller
{
/**
* Show a paginated list of posts.
* Get all of the posts.
*
* @return \Illuminate\View\View
*/
public function index()
{
$data = [
'posts' => Post::orderByDesc('created_at')->with('tags')->get(),
'posts' => Post::orderByDesc('created_at')->get(),
];

return view('canvas::posts.index', compact('data'));
}

/**
* Show the form for creating a new post.
* Create a new post.
*
* @return \Illuminate\View\View
*/
Expand All @@ -43,7 +43,7 @@ public function create()
}

/**
* Show the form for editing an existing post.
* Edit a given post.
*
* @param string $id
* @return \Illuminate\View\View
Expand All @@ -63,7 +63,7 @@ public function edit(string $id)
}

/**
* Store a newly created post in storage.
* Save a new post.
*
* @return \Illuminate\Http\RedirectResponse
*/
Expand Down Expand Up @@ -116,7 +116,7 @@ public function store()
}

/**
* Update a post in storage.
* Save a given post.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand Down Expand Up @@ -171,7 +171,7 @@ public function update(string $id)
}

/**
* Soft delete a post in storage.
* Delete a given post.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand All @@ -185,7 +185,7 @@ public function destroy(string $id)
}

/**
* Collect tags from the request.
* Collect or create given tags.
*
* @param array $incomingTags
* @return array
Expand All @@ -212,7 +212,7 @@ private function collectTags(array $incomingTags): array
}

/**
* Assign a post to a selected topic.
* Collect or create given topics.
*
* @param array $incomingTopics
* @return array
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
class StatsController extends Controller
{
/**
* The number of days to generate statistics for.
* Days in the past to generate statistics for.
*
* @const int
*/
const DAYS_PRIOR = 30;

/**
* Show the overall statistics for all posts.
* Get all of the posts and views.
*
* @return \Illuminate\View\View
*/
Expand Down Expand Up @@ -44,7 +44,7 @@ public function index()
}

/**
* Show data analytics for a single post.
* Get the statistics for a given post.
*
* @param string $id
* @return \Illuminate\View\View
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TagController extends Controller
{
/**
* Show a paginated list of tags.
* Get all of the tags.
*
* @return \Illuminate\View\View
*/
Expand All @@ -24,7 +24,7 @@ public function index()
}

/**
* Show the form for creating a new tag.
* Create a new tag.
*
* @return \Illuminate\View\View
*/
Expand All @@ -38,7 +38,7 @@ public function create()
}

/**
* Show the form for editing a tag.
* Edit a given tag.
*
* @param string $id
* @return \Illuminate\View\View
Expand All @@ -53,7 +53,7 @@ public function edit(string $id)
}

/**
* Store a newly created tag in storage.
* Save a new tag.
*
* @return \Illuminate\Http\RedirectResponse
*/
Expand All @@ -78,7 +78,7 @@ public function store()
}

/**
* Update a tag in storage.
* Save a given tag.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand All @@ -105,7 +105,7 @@ public function update(string $id)
}

/**
* Soft delete a tag in storage.
* Delete a given tag.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Controllers/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TopicController extends Controller
{
/**
* Show a paginated list of topics.
* Get all of the topics.
*
* @return \Illuminate\View\View
*/
Expand All @@ -24,7 +24,7 @@ public function index()
}

/**
* Show the form for creating a new topic.
* Create a new topic.
*
* @return \Illuminate\View\View
*/
Expand All @@ -38,7 +38,7 @@ public function create()
}

/**
* Show the form for editing a topic.
* Edit a given topic.
*
* @param string $id
* @return \Illuminate\View\View
Expand All @@ -53,7 +53,7 @@ public function edit(string $id)
}

/**
* Store a newly created topic in storage.
* Save a new topic.
*
* @return \Illuminate\Http\RedirectResponse
*/
Expand All @@ -78,7 +78,7 @@ public function store()
}

/**
* Update a topic in storage.
* Save a given topic.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand All @@ -105,7 +105,7 @@ public function update(string $id)
}

/**
* Soft delete a topic in storage.
* Delete a given topic.
*
* @param string $id
* @return \Illuminate\Http\RedirectResponse
Expand Down
36 changes: 14 additions & 22 deletions src/Http/Middleware/ViewThrottle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class ViewThrottle
{
/**
* The number of seconds a view will be kept in session.
* The number of seconds until a view expires.
*
* @const int
*/
const EXPIRES = 3600;
const EXPIRES_IN = 3600;

/**
* Handle the incoming request.
Expand All @@ -27,15 +27,14 @@ public function handle(Request $request, Closure $next)
$posts = $this->getViewedPosts();

if (! is_null($posts)) {
$posts = $this->cleanExpiredViews($posts);
$this->storeInSession($posts);
$this->pruneExpiredViews($posts);
}

return $next($request);
}

/**
* Get the viewed posts currently in session.
* Get the viewed posts in session.
*
* @return array|null
*/
Expand All @@ -45,30 +44,23 @@ private function getViewedPosts()
}

/**
* Clean out the expired posts from the session.
* Prune expired posts from the session.
*
* @param array $posts
* @return array
* @return void
*/
private function cleanExpiredViews(array $posts): array
private function pruneExpiredViews(array $posts): void
{
$time = time();

$throttleTime = self::EXPIRES;
$throttleLimit = self::EXPIRES_IN;

return array_filter($posts, function ($timestamp) use ($time, $throttleTime) {
return ($timestamp + $throttleTime) > $time;
});
}
$collection = collect($posts);

/**
* Store posts in the current session.
*
* @param $posts
* @return void
*/
private function storeInSession($posts)
{
session()->put('viewed_posts', $posts);
foreach ($collection as $key => $value) {
if ($value < $time - $throttleLimit) {
session()->forget('viewed_posts.'.$key);
}
}
}
}
Loading

0 comments on commit 707bf7f

Please sign in to comment.