首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >慢速法则查找

慢速法则查找
EN

Stack Overflow用户
提问于 2012-05-05 00:52:08
回答 1查看 1.9K关注 0票数 2

我正在试图弄清楚为什么我的一个理论发现运行得如此慢。我真的不知道从哪里开始,所以请容忍我。

我做了一个非常基本的find来获取一个user对象。这个发现需要大约160毫秒。当我通过phpmyadmin运行查询时,它使用.7ms。

代码语言:javascript
复制
$this->em->find('Entities\User', $userId)

我已经尝试将skip-name-resolve添加到mysql的my.cnf中。用户表中的id字段被编入索引。我真的不知道还能尝试什么。如果我能提供更多的信息,请告诉我。

以下是实体文件:

代码语言:javascript
复制
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;

/** @Entity(repositoryClass = "Entities\UserRepository")
  * @Table(name="user") 
  */
class User extends \Company_Resource_AbstractEntity
{
    /** @Id @Column(type="integer") @GeneratedValue */
    protected $id;
    /** @Column(type="string") */
    protected $name;
    /** @Column(type="string") */
    protected $password;
    /** @Column(type="string") */
    protected $email;
    /** @Column(type="string") */
    protected $first_name;
    /** @Column(type="string") */
    protected $last_name;
    /** @Column(type="integer") */
    protected $password_reset;
    /** @Column(type="string") */
    protected $salt;
    /** @Column(type="integer") */
    protected $active;
    /** @Column(type="string") */
    protected $cookie_hash;

    /**
    * @ManyToOne(targetEntity="Company" , inversedBy="user")
    */
    protected $company;

    /**
    * @ManyToOne(targetEntity="Privilege" , inversedBy="user")
    */
    protected $privilege;

    /**
    * @OneToMany(targetEntity="CompanySubscription" , mappedBy="user")
    */
    protected $subscription;

    /**
    * @OneToMany(targetEntity="EquipmentEvent" , mappedBy="check_in_user")
    */
    protected $check_in;

    /**
    * @OneToMany(targetEntity="EquipmentEvent" , mappedBy="check_out_user")
    */
    protected $check_out;

    /**
    * @OneToMany(targetEntity="GroupEvent" , mappedBy="check_in_user")
    */
    protected $check_in_group;

    /**
    * @OneToMany(targetEntity="GroupEvent" , mappedBy="check_out_user")
    */
    protected $check_out_group;

    /**
    * @OneToMany(targetEntity="Maintenance" , mappedBy="submit_user")
    */
    protected $maintenance_submit;

    /**
    * @OneToMany(targetEntity="Maintenance" , mappedBy="completed_user")
    */
    protected $maintenance_complete;

    /**
    * @OneToMany(targetEntity="UserLogin" , mappedBy="user")
    */
    protected $login;
}

抽象实体:

代码语言:javascript
复制
use \Doctrine\Common\Collections\ArrayCollection;

abstract class Company_Resource_AbstractEntity implements ArrayAccess
{
    public function offsetExists($offset)
    {
        return property_exists($this, $offset);
    }

    // The get/set functions should check to see if an appropriately named function exists before just returning the
    // property.  This way classes can control how data is returned from the object more completely.
    public function offsetGet($offset)
    {
        $property = new Zend_Filter_Word_UnderscoreToCamelCase();
        $method = 'get'. $property->filter($offset);
        return $this->{$method}();
    }

    public function offsetSet($offset, $value)
    {
        $property = new Zend_Filter_Word_UnderscoreToCamelCase();
        $method = 'set'. $property->filter($offset);
        return $this->{$method}($value);
    }

    public function offsetUnset($offset)
    {
        // can't do this
    }

    /*==-====-====-====-====-====-====-====-====-====-====-==*/

    /*
     * Provides magic method access for getFieldName() and setFieldName()
     * where field_name is a simple field and not a relation
     * A special getData implementation returns all of the current object vars
     */
    public function __call($method, $arguments)
    {
        preg_match('@^([a-z]+)(.*)@', $method, $matches);
        $action = $matches[1];
        $property = $matches[2];
        $underscore = new Zend_Filter_Word_CamelCaseToUnderscore();
        $offset = strtolower($underscore->filter($property));
        if ($action == 'get')
        {
            if ($property == 'Data')
                return get_object_vars($this);
            if ($this->offsetExists($offset))
                return $this->{$offset};
            else
                throw new Zend_Exception(sprintf("'%s' does not have property '%s'", get_class($this), $offset));
        }
        else if ($action == 'set')
        {
            if ($this->offsetExists($offset))
                return $this->{$offset} = $arguments[0];
            else
                throw new Zend_Exception(sprintf("'%s' does not have property '%s'", get_class($this), $offset));
        }
        else
            throw new Zend_Exception(sprintf("'%s' does not have method '%s'", get_class($this), $method));
    }
}

find生成的SQL:

代码语言:javascript
复制
SELECT t0.id AS id1, 
t0.name AS name2, 
t0.password AS password3, 
t0.email AS email4, 
t0.first_name AS first_name5, 
t0.last_name AS last_name6, 
t0.password_reset AS password_reset7, 
t0.salt AS salt8, 
t0.active AS active9, 
t0.cookie_hash AS cookie_hash10, 
t0.company_id AS company_id11, 
t0.privilege_id AS privilege_id12 
FROM user t0 WHERE t0.id = ?

有没有人看到什么不对劲的地方,或者知道该怎么做呢?

使用Doctrine 2.2.2。

当我使用phpmyadmin:http://i.imgur.com/wWeGO.png运行查询时得到解释

表模式:http://i.imgur.com/BQsRX.jpg

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-08 17:04:21

我认为我的设置的问题在于文件中的实际行数。教义每次都会通读这些内容。我为元缓存启用了APC,在第一次加载后,加载时间大大减少。没有查询或结果缓存,查询实际上只需要大约6毫秒,这就是我一直以来的目标。真希望我能早点试一下。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10452984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档