Przeglądaj źródła

Merge remote-tracking branch 'origin/develop' into develop

wzq 5 lat temu
rodzic
commit
d9d7172827
3 zmienionych plików z 23 dodań i 4 usunięć
  1. 13 4
      app/Repositories/MusicRepository.php
  2. 1 0
      bootstrap/app.php
  3. 9 0
      config/constants.php

+ 13 - 4
app/Repositories/MusicRepository.php

@@ -7,8 +7,8 @@
  */
 namespace App\Repositories;
 
-use App\Models\PostMusic;
 use App\Models\PostMusicCategoryRel;
+use Illuminate\Support\Facades\Cache;
 
 class MusicRepository
 {
@@ -21,16 +21,25 @@ class MusicRepository
     public function lists($request)
     {
         $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $music_key = config('constants.MUSIC_LIST');
+        if (Cache::has($music_key)) {
+            return Cache::store('redis')->get($music_key);
+        }
 
-        $this->postMusicCategoryRel = $this->postMusicCategoryRel
+        $category_name = '热门';
+        $postMusicCategoryRel = $this->postMusicCategoryRel
             ->join('post_music_category', 'post_music_category.id', '=', 'post_music_category_rel.music_category_id')
             ->join('post_music', 'post_music.id', '=', 'post_music_category_rel.mid')
             ->select('post_music.*')
-            ->where('post_music_category.id', 11)
+            ->where('post_music_category.name', 'like', "%{$category_name}%")
             ->orderBy('id', 'desc')
             ->paginate($perPage);
 
-        return $this->postMusicCategoryRel;
+        if (!Cache::has($music_key)) {
+            Cache::store('redis')->put($music_key, $postMusicCategoryRel, 604800);//一周过期
+        }
+
+        return $postMusicCategoryRel;
     }
 
 

+ 1 - 0
bootstrap/app.php

@@ -34,6 +34,7 @@ $app->configure('database');
 $app->configure('elasticsearch');
 $app->configure('aliyun');
 $app->configure('aliyunvod');
+$app->configure('constants');
 /*
 |--------------------------------------------------------------------------
 | Register Container Bindings

+ 9 - 0
config/constants.php

@@ -0,0 +1,9 @@
+<?php
+
+/**
+ * 常量配置
+ */
+
+return [
+    'MUSIC_LIST' => env('REDIS_MUSIC_LIST', 'music_list'),
+];