Oct
2
When Doctrine leftJoin fails
Filed Under PHP, Symfony | Leave a Comment
I’ve stumbled across a weired problem in Symfony, using Doctrine. Whenever I wanted to use a leftJoin, stuff would fail. So, here are some tips to help you pass this problems:
1. Check that the leftJoin is issued like $q->(a.RelationshipName r);
where “a” is the root alias of the query, RelationshipName is the NAME of the relationship defined in the yaml file of the database.
2. Make sure you use the actual relationship name from the yaml DB schema, and not the class name or something else. For instance, let’s say you have 2 classes: MysiteArticle and MysiteCategory. To fetch articles, you would build your query like: Doctrine_Query::create()->from(’MysiteArticle a’);
But, to fetch articles together with the category, you would do something like:
Doctrine_Query::create()->from(’MysiteArticle a’)->leftJoin(’a.Category c’); if your relationship name is “Category”, in the schema.yml, or Doctrine_Query::create()->from(’MysiteArticle a’)->leftJoin(’a.MysiteCategory c’); if your relationship name is MysiteCategory.
Dec
18
Getting the cursor position inside a text-field and smart ways to build form validators
Filed Under JavaScript, Uncategorized | 1 Comment
I have always wanted a nice clean way to build form validators based on any kind of rule i would choose, however most of the times I stumbled upon a simple problem: How to get the cursor position inside a text-field? It’s easy in Mozilla, but what about IE?
The challenge was weird, but I finally got a way around, starting an idea here.
What I’ve done is I used Prototype to extend the Form Element Methods and simply add a version of selectionStart and selectionEnd for IE. After that, I just put them to work in a nice input wrapper class.
Read more
Dec
18
Quick quide to regular expressions in JavaScript
1. The form of an expression:
var a = /dog/gim
//dog = the expression to match, g = search all matches, i = case insensitive, m=multiple line
The cool thing is that /dog/ is an object, so you can, for example, do something like /dog/.test(something)
Read more
Dec
11
Database sharding unraveled - part IV
Filed Under MySQL, Scalability tools, Uncategorized | Leave a Comment
Continuing the series about Database Sharding, I’m going to to talk about the software/hardware architecture. This post started from an excellent read, MySQL Database Scale-out and Replication for High Growth Businesses.
The first order of business is MySQL replication. Replication is needed to offer redundancy and to distribute even further the load on the system. In a typicall shard environment, the database is split among multiple servers, with data being unique to each server. If one of the servers goes down, all that data will become unavailable, and even though the system will continue working, parts of some scenarios will fail. This is where replication comes to stage.
Read more
Oct
7
Smart trick to check some bottlenecks in your DB
Filed Under MySQL, Scalability tools | Leave a Comment
There’s a nice tool called iostat to check the HDD related info, like number of reads/writes, amount of data processed, etc. It’s a must have for any good sysadmin, as it allows you to identify some of the bottlenecks in the DB.
Together with the vmstat tool - allows a user to see statistics for the virtual memory usage - form a powerful duo to use, especially when your DB is running very slow, but the processors are not fully used.
The tools have enough explanations on the man pages.
So, the only thing remaining is to start them up:
Open 2 terminal windows. The first one would run something like iostat -dx 10 (will display the device extended report, refreshed every 10 seconds - you can increase/decrease this number to suite your needs - too small is not very good, as it’s better to have stats over a longer period). The second one should run vmstat 10.
Last but not least, to get them you need to install the sysstat package (vmstat is in the procps package, installed by default). For ubuntu, type: sudo apt-get install sysstat.
