在symfony2,doctrine2中,我有一个触发错误的查询:
Error "1038 Out of sort memory, consider increasing server sort buffer size
Run Code Online (Sandbox Code Playgroud)
查询:
$queryBuilder = $this
->createQueryBuilder('object')
->leftJoin('object.objectCategory', 'c')
->leftJoin('object.medias', 'm')
->leftJoin('object.recipients', 'r')
->leftJoin('object.answers', 'a')
->leftJoin('object.tags', 't')
->leftJoin('object.user', 'u')
->leftJoin('object.votes', 'v')
->leftJoin('object.comments', 'comments')
->leftJoin('v.user', 'vuser')
->addSelect('c, t, v, u')
->groupBy('object, c, t, v, u')
->where('object.isVisible = :isVisible')
->orderBy('object.createdAt', 'DESC')
->setParameter('isVisible', true)
->addSelect('SUM(v.value) AS HIDDEN vote_value')
->orderBy('vote_value', 'DESC')
;
Run Code Online (Sandbox Code Playgroud)
如果我省略了分组,它运行得很好.如果我用较少的元素添加select和group,它也运行正常但是我在我的twig模板中启动了更多的子查询.
如何优化此查询以避免错误或通过分配更多内存(理想情况下仅用于此查询)来消除错误?
我刚刚在 linux 14.10 上切换到 systemd,现在我的 elasticsearch 服务无法正常启动
elasticsearch.service loaded failed failed
Run Code Online (Sandbox Code Playgroud)
asystemctl status给了我以下内容:
elasticsearch.service - Starts and stops a single elasticsearch instance on this system
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled)
Active: failed (Result: exit-code) since Mon 2015-04-13 23:23:54 CEST; 4s ago
Docs: http://www.elasticsearch.org
Process: 1227 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -Des.default.config=$CONF_FILE -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR (code=exited, status=3)
Main PID: 1227 (code=exited, status=3)
Run Code Online (Sandbox Code Playgroud)
我没有管理服务方面的经验,而且我对 systemd 还很陌生,所以我不知道如何解决这个问题。
有人可以指出我正确的方向吗?谢谢 !
在我的应用程序中,我想在不丢失数据的情况下将一对多转换为多对多:
从:
/**
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\FoodAnalytics\Recipe", inversedBy="medias")
* @ORM\JoinColumn(name="recipeId", referencedColumnName="id", onDelete="CASCADE")
*/
protected $recipe;
Run Code Online (Sandbox Code Playgroud)
至:
/**
* @ORM\ManyToMany(targetEntity="\AppBundle\Entity\FoodAnalytics\Recipe", inversedBy="medias")
* @ORM\JoinTable(
* name="media_recipes",
* joinColumns={@ORM\JoinColumn(name="mediaId", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="recipeId", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $recipes;
Run Code Online (Sandbox Code Playgroud)
当我抛弃我的学说谢谢更新时,它说它会丢弃数据,而不是我想要的:
CREATE TABLE media_recipes (mediaId INT UNSIGNED NOT NULL, recipeId INT UNSIGNED NOT NULL, INDEX IDX_C2BE64FC27D9F5AC (mediaId), INDEX IDX_C2BE64FC6DCBA54 (recipeId), PRIMARY KEY(mediaId, recipeId)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE media_recipes ADD CONSTRAINT FK_C2BE64FC27D9F5AC FOREIGN KEY (mediaId) REFERENCES media (id) ON …Run Code Online (Sandbox Code Playgroud) 我正在尝试优化我的 google pagespeed Insights 分数,我得出的结论是,推迟 nextjs 的 NextScript 还不够好,它仍然会导致不良的 LCP 和 TII。
我有以下代码。
如何捆绑我正在循环的脚本,以便在 window.onload 事件之后加载它们?
任何帮助将非常感激。
import { NextScript } from 'next/document';
import React from 'react';
type DocumentFiles = {
sharedFiles: readonly string[];
pageFiles: readonly string[];
allFiles: readonly string[];
};
function dedupe<T extends { file: string }>(bundles: T[]): T[] {
const files = new Set<string>();
const kept: T[] = [];
// eslint-disable-next-line
for (const bundle of bundles) {
if (files.has(bundle.file)) {
// eslint-disable-next-line
continue;
}
files.add(bundle.file);
kept.push(bundle);
}
return …Run Code Online (Sandbox Code Playgroud) 我正在使用symfony 2,我有一个表格,我在其上放置@Assert\NotBlank()注释.我正在填充字段,我的表单没有通过isValid和isSubmitted测试,在这些行之后我得到一个非null值的退出(var_dump($ recipeForm-> getErrors()));
private 'errors' =>
array (size=4)
0 =>
object(Symfony\Component\Form\FormError)[4119]
private 'message' => string 'Cette valeur doit être vide.' (length=29)
protected 'messageTemplate' => string 'This value should be blank.' (length=27)
protected 'messageParameters' =>
array (size=1)
...
protected 'messagePluralization' => null
private 'cause' =>
object(Symfony\Component\Validator\ConstraintViolation)[4062]
...
private 'origin' => null
Run Code Online (Sandbox Code Playgroud)
在我的twig模板中,我使用简单的表单(表单)渲染表单.form_errors(form)或form_errors(form.field)不会呈现错误.为什么?我为什么要进一步了解问题的来源?
我有一个非常复杂的类型.对于我网站的其他一些形式,错误被正确显示.我的风格:
<?php
//src/AppBundle/Form/FoodAnalytics/RecipeType.php
namespace AppBundle\Form\FoodAnalytics;
use AppBundle\Form\Core\MediaType;
use AppBundle\Repository\FoodAnalytics\UnitRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class RecipeType extends AbstractType
{
protected $recipeIngredientQueryBuilder;
protected $recipeSubrecipeQueryBuilder;
protected $unitRepository;
protected $action; …Run Code Online (Sandbox Code Playgroud) 在我的symfony2/doctrine2应用程序中,我有一个奇怪的情况,当持久化修改后的实体时,更改不会刷新到数据库,我无法理解为什么.
以下是我的代码:
$date = $subscription->getPaymentValidUntil()->format('d/m/Y');
$period = $payment->getDetail('period');
$validDate = $subscription->getPaymentValidUntil()
->add(new\DateInterval($period == Subscription::MONTH ? 'P1M' : 'P1Y'))
;
$subscription->setPaymentValidUntil($validDate);
$this->em->persist($subscription);
exit(var_dump(array(
$date,
$this->em->getUnitOfWork()->getScheduledEntityUpdates(),
$subscription->getPaymentValidUntil(),
)));
$this->em->flush();
Run Code Online (Sandbox Code Playgroud)
vardump的输出如下:
array (size=3)
0 => string '12/05/2015' (length=10)
1 =>
array (size=0)
empty
2 =>
object(DateTime)[2295]
public 'date' => string '2015-06-12 18:52:37' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
Run Code Online (Sandbox Code Playgroud)
如果我在vardump之前刷新或删除vardump,事实上,我的数据库中的日期值不会改变.为什么?
正如您所看到的,我将这个日期值添加一个月,它反映在实体中,但它没有安排更新.我怎么解决这个问题?
编辑:我已经深入了解实体管理器持久化函数,我发现当在Doctrine\ORM\EntityManager :: persist中转储实体时,日期很好,但是当它在Doctrine\ORM\UnitOfWork :: persist中转储时,日期以某种方式重置了原来的:
Doctrine\ORM\EntityManager::persist :转储更新的实体
public function persist($entity)
{
if ( ! is_object($entity)) {
throw …Run Code Online (Sandbox Code Playgroud) 在我的 symfony2 应用程序中,我使用 FOS Elastica 捆绑包来执行搜索。
我尝试设置分析器和过滤器,但似乎它们没有效果。例如,如果我搜索单词“蛋糕”,则不会返回包含句子大小写“蛋糕”的对象。
如何正确配置这些分析器和过滤器?
我的配置:
#Elastic Search
fos_elastica:
default_manager: orm
clients:
default: { host: localhost, port: 9200 }
indexes:
website:
client: default
settings:
index:
analysis:
analyzer:
custom_index_analyzer :
type : custom
tokenizer: nGram
filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
custom_search_analyzer :
type : custom
tokenizer: nGram
filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
tokenizer:
nGram:
type: nGram
min_gram: 1
max_gram: 2
filter:
snowball:
type: snowball
language: French
elision:
type: elision
articles: [l, m, …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的函数,用js渲染模板.我想它自动调用所以我已经将is_safe参数设置为array(html')而不必使用| raw filter
但它不起作用,jsis没有转义,而是呈现为纯文本.如果我使用原始过滤器,它可以正常工作.
我怎么解决这个问题?
我的简单功能:
<?php
namespace AppBundle\Extension\Twig;
use AppBundle\FoodMeUpParameters;
use AppBundle\Model\Interfaces\ViewCountInterface;
use ReflectionClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FMUTwigExtension extends \Twig_Extension
{
/**
* @var ContainerInterface
*/
private $container;
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}
public function getFunctions()
{
return array(
'increaseViewCount' => new \Twig_SimpleFunction('increaseViewCount', array($this, 'increaseViewCount', array('is_safe' => array('html')))),
);
}
public function increaseViewCount(ViewCountInterface $entity, $andFlush = true)
{
$reflect = new ReflectionClass($entity);
$parameters = array(
'short_name' => $reflect->getShortName(),
'identifier' => $entity->getId(),
'and_flush' => $andFlush
); …Run Code Online (Sandbox Code Playgroud) 使用带有doctrine树扩展的symfony2和doctrine2,我最近更新了一个实体,使其成为一个学说嵌套集树.
doctrine架构更新强制使用空数据添加了正确的列.
然后我运行了以下代码:
$repo = $this->getDoctrine()->getRepository('AppBundle:FoodAnalytics\Recipe');
$repo->verify();
// can return TRUE if tree is valid, or array of errors found on tree
$repo->recover();
$this->flush(); // important: flush recovered nodes
// if tree has errors it will try to fix all tree
Run Code Online (Sandbox Code Playgroud)
它成功恢复了左右和水平值但不是root.我无法手动设置根值(由doctrine listener禁止).
如何更新这些根值以使树能够正常工作?
谢谢 !
在我的Dymfony2/Doctrine2应用程序中,我在对象及其子对象之间存在oneToMany关系.
我想选择所有没有孩子的物品.
我遇到了各种错误:期望SingleValuedAssociationField,无法添加非结果变量等等.
$queryBuilder = $this
->createQueryBuilder('object')
->leftJoin('object.children', 'children')
->andWhere('children IS NULL')
// tested with a parameter, with addselect COUNT(children) and 0 condition, etc.
->getQuery()
->getResult();
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
symfony ×8
doctrine-orm ×5
php ×3
javascript ×2
mysql ×2
twig ×2
analyzer ×1
associations ×1
doctrine ×1
elastica ×1
escaping ×1
filter ×1
forms ×1
linux ×1
nested ×1
next.js ×1
one-to-many ×1
onload ×1
pagespeed ×1
reactjs ×1
search ×1
service ×1
sql ×1
systemd ×1
tree ×1
ubuntu-14.10 ×1
unit-of-work ×1
validation ×1