teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

19

更新

2017/10/05 16:34

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -5,6 +5,9 @@
5
5
  どうしてそうなるのかがわかっておらず、したがってどう対処すればよいのかわかっておりません。
6
6
  ご教授いただければ幸いです。
7
7
 
8
+ ※変数に格納してあるデータが1Mちょうどで収まっているのを確認しました。つまり1Mを超えたデータについては切られている状況になります。
9
+ そのため、json配列の「 ] 」も切られているので、nullが取得されていると考えています。
10
+
8
11
  ###コード
9
12
  ```
10
13
  protected $casts = array(

18

更新

2017/10/05 16:34

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,12 @@
7
7
 
8
8
  ###コード
9
9
  ```
10
+ protected $casts = array(
11
+ 'result' => 'array',
12
+ 'query' => 'array',
13
+ );
14
+ ```
15
+ ```
10
16
  $data = Search::select('result', 'query')->where('id', 5)->first();
11
17
  $all = $data ? $data['result'] : [];
12
18
  ```

17

一部更新

2017/10/05 16:29

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 【laravel】DBに保存されている配列がnullになり取得できない(取得するjson配列が途中で切れる)
1
+ 【laravel・RDS】DBに保存されている配列がnullになり取得できない(取得するjson配列が途中で切れる)
body CHANGED
File without changes

16

現状報告

2017/10/05 12:20

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -141,6 +141,10 @@
141
141
 
142
142
  「RIGHT(result, 10)」:1576,3449]
143
143
 
144
+ ##現状報告
145
+ 調べたところ、1MBを境目にエラーが発生しているようです。
146
+ そのため、phpとmysqlの設定をあらっている現状になります。
147
+
144
148
  ####バージョン
145
149
  php7
146
150
  laravel5.1

15

DBはRDSを使っています

2017/10/05 11:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -143,4 +143,5 @@
143
143
 
144
144
  ####バージョン
145
145
  php7
146
- laravel5.1
146
+ laravel5.1
147
+ データベース:RDS(mysql5.7)

14

タイトル追加

2017/10/05 10:32

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 【laravel】DBに保存されている配列がnullになり取得できない
1
+ 【laravel】DBに保存されている配列がnullになり取得できない(取得するjson配列が途中で切れる)
body CHANGED
File without changes

13

更新

2017/10/05 10:04

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes

12

更新

2017/10/05 09:50

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -137,8 +137,10 @@
137
137
 
138
138
  「substr(getAttribute['result'], -10)」:"7392,7372,"
139
139
 
140
- 「LENGTH(result)」「RIGHT(result, 10)」1576,3449]
140
+ 「LENGTH(result)」:1053784
141
141
 
142
+ 「RIGHT(result, 10)」:1576,3449]
143
+
142
144
  ####バージョン
143
145
  php7
144
146
  laravel5.1

11

追記

2017/10/05 09:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -137,4 +137,8 @@
137
137
 
138
138
  「substr(getAttribute['result'], -10)」:"7392,7372,"
139
139
 
140
- 「LENGTH(result)」「RIGHT(result, 10)」:1576,3449]
140
+ 「LENGTH(result)」「RIGHT(result, 10)」:1576,3449]
141
+
142
+ ####バージョン
143
+ php7
144
+ laravel5.1

10

更新

2017/10/05 09:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -131,4 +131,10 @@
131
131
  return array_values(array_intersect(array_map('intval', $fulltext->lists('main_id')->toArray()), $ids));
132
132
  }
133
133
  }
134
- ```
134
+ ```
135
+ ###追記②
136
+ 「strlen(getAttribute['result'])」:1041645
137
+
138
+ 「substr(getAttribute['result'], -10)」:"7392,7372,"
139
+
140
+ 「LENGTH(result)」「RIGHT(result, 10)」:1576,3449]

9

わからないこと修正

2017/10/05 08:59

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,8 @@
1
1
  ###わからないこと
2
2
  配列でIDを取得してそれをもとに一覧ページを表示しています。
3
3
  しかし、該当箇所でnullとなり、dd()で確認したところ、配列が途中までしか表示されておりませんでした。
4
- おそらく配列が完全に取得されいから(角括弧が閉じられていない状況す)nullとなってしまうと考えております。
4
+ すべの表示結果でそうるわけはなく一定数以上の件数でのみそうなっており、データ量が影響ているのではと考えております。
5
- ただ、どうしてそうなるのかがわかっておらず、したがってどう対処すればよいのかわかっておりません。
5
+ どうしてそうなるのかがわかっておらず、したがってどう対処すればよいのかわかっておりません。
6
6
  ご教授いただければ幸いです。
7
7
 
8
8
  ###コード

8

更新

2017/10/05 06:10

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -81,9 +81,54 @@
81
81
 
82
82
  ##追記
83
83
  ```
84
+ $search = (int)request()->input('search');
85
+ if ($search) {
86
+ $data = Search::select('result', 'query')->where('id', $search)->first();
87
+ dd(strlen($data->getAttributeFromArray('result')));
88
+ $all = $data ? $data['result'] : [];
89
+ $q = isset($data['query']['q']) ? $data['query']['q'] : '';
90
+ $phaseIds[0] = isset($data['query']['phase']) ? $data['query']['phase'] : [];
91
+ $privacy = isset($data['query']['privacy']) ? $data['query']['privacy'] : [];
92
+ } else {
93
+ $phaseIds[0] = array_unique(array_map('intval', (array)request()->input('phase')));
94
+ if ($phaseIds[0]) {
95
+ } elseif (request()->ajax()) {
96
+ unset($phaseIds[0]);
97
+ unset($phaseIds[1]);
98
+ $phaseIds = array_values($phaseIds);
99
+ } else {
100
+ $phaseIds[0] = array_values(array_diff(last($phaseIds),(array)Option::getArray(Option::JPHASE_FINISH)));
101
+ }
102
+ // 検索フォームでの検索値の取得
103
+ $q = (string)request()->input('q');
104
+ // 各種ポータルサイトへの公開/非公開設定の取得
105
+ $privacy = array_unique((array)request()->input('privacy'));
106
+ // 全案件のidを取得
84
- $all = self::commitSearch($q, $phaseIds[0], $privacy);
107
+ $all = self::commitSearch($q, $phaseIds[0], $privacy);
85
- // インスタンスの生成
108
+ // インスタンスの生成
86
- $search = new Search();
109
+ $search = new Search();
87
- $search['result'] = $all;
110
+ $search['result'] = $all;
111
+ $search['query'] = ['phase'=>$phaseIds[0],'q'=>$q,'privacy'=>$privacy];
112
+ $search->save();
113
+ $search = $search['id'];
114
+ }
88
115
 
116
+ ```
117
+ ```
118
+ public static function commitSearch($q, $phaseIds, $privacy, $ids = NULL) {
119
+ $fulltext = Fulltext::where('type', 'job')->orderBy('time','DESC');
120
+ if ($ids) $fulltext->whereIn('main_id', $ids);
121
+ if ($phaseIds) $fulltext->whereIn('phase_id', $phaseIds);
122
+ if ($q !== '') $fulltext->whereIndex($q);
123
+ if (!$privacy || count($privacy) === 3) {
124
+ return array_map('intval', $fulltext->lists('main_id')->toArray());
125
+ } elseif (!($ids = array_map('intval', Job::whereIn('privacy', $privacy)->lists('id')->toArray()))) {
126
+ return [];
127
+ } elseif (count($ids) <= 10000) {
128
+ $fulltext->whereIn('main_id', $ids);
129
+ return array_map('intval', $fulltext->lists('main_id')->toArray());
130
+ } else {
131
+ return array_values(array_intersect(array_map('intval', $fulltext->lists('main_id')->toArray()), $ids));
132
+ }
133
+ }
89
134
  ```

7

一部追記

2017/10/05 06:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -77,4 +77,13 @@
77
77
  "result" => "[142264,142265,142266,142263,142262,142261,142260,...]
78
78
  "query" => "{"phase":[1,2,3,5,6,8,12,32,10,11,28,29,27,26,25,31,24,0],"q":"","privacy":[]}"
79
79
  ]
80
+ ```
81
+
82
+ ##追記
83
+ ```
84
+ $all = self::commitSearch($q, $phaseIds[0], $privacy);
85
+ // インスタンスの生成
86
+ $search = new Search();
87
+ $search['result'] = $all;
88
+
80
89
  ```

6

更新

2017/10/05 05:44

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -75,4 +75,6 @@
75
75
  +timestamps: true
76
76
  #attributes: array:2 [▼
77
77
  "result" => "[142264,142265,142266,142263,142262,142261,142260,...]
78
+ "query" => "{"phase":[1,2,3,5,6,8,12,32,10,11,28,29,27,26,25,31,24,0],"q":"","privacy":[]}"
79
+ ]
78
80
  ```

5

追加

2017/10/05 05:13

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,17 @@
62
62
  "q" => ""
63
63
  "pri" => []
64
64
  ]
65
+ ```
66
+ ###ddの結果
67
+ ```
68
+ Search {#987 ▼
69
+ #table: "searches"
70
+ #casts: array:3 [▶]
71
+ #connection: null
72
+ #primaryKey: "id"
73
+ #perPage: 15
74
+ +incrementing: true
75
+ +timestamps: true
76
+ #attributes: array:2 [▼
77
+ "result" => "[142264,142265,142266,142263,142262,142261,142260,...]
65
78
  ```

4

更新

2017/10/05 05:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -58,8 +58,8 @@
58
58
  ###queryの中身
59
59
  ```
60
60
  array:3 [▼
61
- "phase" => array:18 [▶]
61
+ "pha" => array:18 [▶]
62
62
  "q" => ""
63
- "privacy" => []
63
+ "pri" => []
64
64
  ]
65
65
  ```

3

追記

2017/10/04 08:19

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -54,4 +54,12 @@
54
54
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
55
55
  PRIMARY KEY (`id`)
56
56
  ) ENGINE=InnoDB AUTO_INCREMENT=89390 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_c
57
+ ```
58
+ ###queryの中身
59
+ ```
60
+ array:3 [▼
61
+ "phase" => array:18 [▶]
62
+ "q" => ""
63
+ "privacy" => []
64
+ ]
57
65
  ```

2

追記

2017/10/04 08:19

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,9 @@
8
8
  ###コード
9
9
  ```
10
10
  $data = Search::select('result', 'query')->where('id', 5)->first();
11
+ $all = $data ? $data['result'] : [];
11
12
  ```
13
+ 上記の「$data['result']」にddをかけるとnullが取得されます。
12
14
  ※Searchはsearchesというテーブルを指します。
13
15
  そのうちの「result」カラムが非常に肥大している状況です。
14
16
  通常ですと、「result:[1, 2, 3, ..., 555555]」のように表示されるのですが、「 result:[1, 2, 3, ..., 555554, 」と表示されています。

1

追記

2017/10/04 08:04

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -32,4 +32,24 @@
32
32
  Create_options:
33
33
  Comment:
34
34
 
35
- よろしくお願いいたします。
35
+ よろしくお願いいたします。
36
+ ##追加事項
37
+ ###モデル
38
+ ```
39
+ protected $table = 'searches';
40
+ protected $casts = array(
41
+ 'id' => 'integer',
42
+ 'result' => 'array',
43
+ 'query' => 'array',
44
+ );
45
+ ```
46
+ ###テーブル構造
47
+ ```
48
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
49
+ `result` longtext COLLATE utf8_unicode_ci NOT NULL,
50
+ `query` longtext COLLATE utf8_unicode_ci NOT NULL,
51
+ `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
52
+ `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB AUTO_INCREMENT=89390 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_c
55
+ ```