mirror of
https://github.com/openclassify/openclassify.git
synced 2026-03-10 10:15:28 -05:00
Level and ad count optimisations for OC 2.0 update
This commit is contained in:
parent
90397a8126
commit
7a26b27f88
@ -5,7 +5,7 @@
|
||||
<b>{{ main_category.name }}</b>
|
||||
{% if showAdsCount %}
|
||||
<small class="text-muted">
|
||||
({{ main_category.adcount }})
|
||||
({{ main_category.count }})
|
||||
</small>
|
||||
{% endif %}
|
||||
</a>
|
||||
@ -25,7 +25,7 @@
|
||||
class="">{{ subcats.c2_name }}</a>
|
||||
{% if showAdsCount %}
|
||||
<small class="text-muted">
|
||||
({{ subcats.adcount }})
|
||||
({{ subcats.c2_count }})
|
||||
</small>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Anomaly\Streams\Platform\Database\Migration\Migration;
|
||||
|
||||
class VisiosoftModuleCatsAdcount extends Migration
|
||||
{
|
||||
|
||||
protected $stream = [
|
||||
'slug' => 'category',
|
||||
];
|
||||
|
||||
protected $fields = [
|
||||
'adcount' => 'anomaly.field_type.integer',
|
||||
'adcount_updateat' => 'anomaly.field_type.datetime'
|
||||
];
|
||||
|
||||
protected $assignments = [
|
||||
'adcount' => []
|
||||
];
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Anomaly\Streams\Platform\Database\Migration\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class VisiosoftModuleCatsAdcountLevel extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::table('cats_category', function (Blueprint $table) {
|
||||
$table->integer('level');
|
||||
$table->datetime('level_at');
|
||||
$table->integer('count');
|
||||
$table->datetime('count_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -48,11 +48,13 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
->select(
|
||||
DB::raw('c1.id'),
|
||||
DB::raw('c1.slug'),
|
||||
DB::raw('c1.count'),
|
||||
DB::raw('c1.parent_category_id'),
|
||||
DB::raw('t1.name'),
|
||||
|
||||
DB::raw('c2.id as c2_id'),
|
||||
DB::raw('c2.slug as c2_slug'),
|
||||
DB::raw('c2.count as c2_count'),
|
||||
DB::raw('c2.parent_category_id as c2_parent_category_id'),
|
||||
DB::raw('t2.name as c2_name')
|
||||
)
|
||||
|
||||
@ -17,6 +17,12 @@ class CategoryTableBuilder extends TableBuilder
|
||||
'clean_subcategories' => [
|
||||
'href' => '/admin/cats/clean_subcats',
|
||||
],
|
||||
'adcountcalc' => [
|
||||
'href' => '/admin/cats/adcountcalc',
|
||||
],
|
||||
'catLevelCalc' => [
|
||||
'href' => '/admin/cats/catlevelcalc',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -47,6 +47,8 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
||||
*/
|
||||
protected $routes = [
|
||||
'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubcats',
|
||||
'admin/cats/adcountcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@adCountCalc',
|
||||
'admin/cats/catlevelcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@catLevelCalc',
|
||||
|
||||
'admin/cats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index',
|
||||
'admin/cats/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create',
|
||||
|
||||
@ -2,13 +2,16 @@
|
||||
|
||||
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
|
||||
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
||||
use Visiosoft\CatsModule\Category\Form\CategoryFormBuilder;
|
||||
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
|
||||
|
||||
class CategoryController extends AdminController
|
||||
{
|
||||
@ -208,5 +211,54 @@ class CategoryController extends AdminController
|
||||
}
|
||||
return redirect('admin/cats')->with('success', [$deletedCatsCount . ' categories has been deleted.']);
|
||||
}
|
||||
public function adCountCalc(AdvRepositoryInterface $advRepository)
|
||||
{
|
||||
$date = new DateTime;
|
||||
$date2 = new DateTime;
|
||||
$date->modify('-30 minutes');
|
||||
$formatted_date = $date->format('Y-m-d H:i:s');
|
||||
|
||||
$result = DB::table('cats_category')
|
||||
->select('id','level')
|
||||
->where('count_at','<',$formatted_date)
|
||||
->orWhereNull('count_at')
|
||||
->get();
|
||||
foreach ($result as $key => $data) {
|
||||
$id = $data->id;
|
||||
$level = $data->level;
|
||||
if(!empty($level)) {
|
||||
$count = $advRepository->countByCat($id, $level);
|
||||
DB::table('cats_category')->where('id',$id)->update(array(
|
||||
'count'=>$count,
|
||||
'count_at'=>$date2,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
public function catLevelCalc()
|
||||
{
|
||||
$date = new DateTime;
|
||||
$date2 = new DateTime;
|
||||
$date->modify('-30 minutes');
|
||||
$formatted_date = $date->format('Y-m-d H:i:s');
|
||||
|
||||
$result = DB::table('cats_category')
|
||||
->select('id')
|
||||
->where('level_at','<',$formatted_date)
|
||||
->where('level','=',0)
|
||||
->orWhereNull('level_at')
|
||||
->get();
|
||||
foreach ($result as $key => $data) {
|
||||
$id = $data->id;
|
||||
$CategoriesModel = new CategoryModel();
|
||||
$level = $CategoriesModel->getCatLevel($id);
|
||||
|
||||
DB::table('cats_category')->where('id',$id)->update(array(
|
||||
'level'=>$level,
|
||||
'level_at'=>$date2,
|
||||
));
|
||||
}
|
||||
return redirect('admin/cats')->with('success', ['Updated']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user