Added information about post space usage

This commit is contained in:
Marcin Kurczewski 2014-05-14 20:06:16 +02:00
parent d082d74716
commit 66039e56a6
4 changed files with 34 additions and 1 deletions

View file

@ -6,6 +6,7 @@ class StaticPagesController
$context = getContext();
$context->transport->postCount = PostModel::getCount();
$context->viewName = 'static-main';
$context->transport->postSpaceUsage = PostModel::getSpaceUsage();
PostModel::featureRandomPostIfNecessary();
$featuredPost = PostModel::getFeaturedPost();

View file

@ -313,6 +313,32 @@ final class PostModel extends AbstractCrudModel
public static function getSpaceUsage()
{
$unixTime = PropertyModel::get(PropertyModel::PostSpaceUsageUnixTime);
if (($unixTime !== null) and (time() - $unixTime < 24 * 60 * 60))
return PropertyModel::get(PropertyModel::PostSpaceUsage);
$totalBytes = 0;
$paths = [getConfig()->main->filesPath, getConfig()->main->thumbsPath];
foreach ($paths as $path)
{
$iterator =
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$path, FilesystemIterator::SKIP_DOTS));
foreach ($iterator as $object)
$totalBytes += $object->getSize();
}
PropertyModel::set(PropertyModel::PostSpaceUsage, $totalBytes);
PropertyModel::set(PropertyModel::PostSpaceUsageUnixTime, time());
return $totalBytes;
}
public static function getFeaturedPost()
{
$featuredPostId = PropertyModel::get(PropertyModel::FeaturedPostId);

View file

@ -8,6 +8,8 @@ final class PropertyModel implements IModel
const FeaturedPostUserName = 1;
const FeaturedPostUnixTime = 2;
const DbVersion = 3;
const PostSpaceUsage = 4;
const PostSpaceUsageUnixTime = 5;
static $allProperties;
static $loaded;

View file

@ -6,7 +6,11 @@ Assets::addStylesheet('static-main.css');
<div id="welcome">
<h1><?= getConfig()->main->title ?></h1>
<p>
<span>serving <?= $this->context->transport->postCount ?> posts</span>
<span>
<?php printf('serving %d posts (%s)',
$this->context->transport->postCount,
TextHelper::useBytesUnits($this->context->transport->postSpaceUsage)) ?>
</span>
</p>
</div>