r89294 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89293‎ | r89294 | r89295 >
Date:21:44, 1 June 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
return the campaigns in the banner lists - 1st step for new tracking features
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -132,37 +132,36 @@
133133 $templates = array();
134134
135135 if ( $campaigns ) {
136 - // Pull templates based on join with assignments
137 - $res = $dbr->select(
138 - array(
139 - 'cn_notices',
140 - 'cn_assignments',
141 - 'cn_templates'
142 - ),
143 - array(
144 - 'tmp_name',
145 - 'SUM(tmp_weight) AS total_weight',
146 - 'tmp_display_anon',
147 - 'tmp_display_account'
148 - ),
149 - array(
150 - 'cn_notices.not_id' => $campaigns,
151 - 'cn_notices.not_id = cn_assignments.not_id',
152 - 'cn_assignments.tmp_id = cn_templates.tmp_id'
153 - ),
154 - __METHOD__,
155 - array(
156 - 'GROUP BY' => 'tmp_name'
157 - )
158 - );
159 -
160 - foreach ( $res as $row ) {
161 - $templates[] = array(
162 - 'name' => $row->tmp_name,
163 - 'weight' => intval( $row->total_weight ),
164 - 'display_anon' => intval( $row->tmp_display_anon ),
165 - 'display_account' => intval( $row->tmp_display_account ),
 136+ foreach ( $campaigns as $campaignId ) {
 137+ $res = $dbr->select(
 138+ array(
 139+ 'cn_notices',
 140+ 'cn_assignments',
 141+ 'cn_templates'
 142+ ),
 143+ array(
 144+ 'tmp_name',
 145+ 'tmp_weight',
 146+ 'tmp_display_anon',
 147+ 'tmp_display_account'
 148+ ),
 149+ array(
 150+ 'cn_notices.not_id' => $campaignId,
 151+ 'cn_notices.not_id = cn_assignments.not_id',
 152+ 'cn_assignments.tmp_id = cn_templates.tmp_id'
 153+ ),
 154+ __METHOD__
166155 );
 156+
 157+ foreach ( $res as $row ) {
 158+ $templates[] = array(
 159+ 'name' => $row->tmp_name,
 160+ 'weight' => intval( $row->tmp_weight ),
 161+ 'display_anon' => intval( $row->tmp_display_anon ),
 162+ 'display_account' => intval( $row->tmp_display_account ),
 163+ 'campaign' => CentralNotice::getNoticeName( $campaignId ),
 164+ );
 165+ }
167166 }
168167 }
169168 return $templates;

Follow-up revisions

RevisionCommit summaryAuthorDate
r90642pull banners with a single db query per comment at r89294kaldari00:55, 23 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   19:30, 3 June 2011

Why run multiple queries rather than selecting not_id along with the other fields?

#Comment by Brion VIBBER (talk | contribs)   19:31, 3 June 2011

Hmm.. if a banner is in multiple campaigns does this mean we end up with multiple entries for it, each with a different campaign ID?

#Comment by Kaldari (talk | contribs)   20:04, 3 June 2011

Exactly. The reason for this change is that the fundraising people want each banner to report which campaign the banner was served from for tracking purposes. Previously, we were just aggregating all the instances of a single banner together and summing the weights (which lost the campaign association).

#Comment by Brion VIBBER (talk | contribs)   20:57, 3 June 2011

Excellent. :D Looks like it should work fine with the current selection algorithm (most of that JS still hides in SpecialBannerController.php, eek! :)

#Comment by Brion VIBBER (talk | contribs)   20:58, 3 June 2011

Actually it might work to do a single query with different grouping.... but it probably doesn't make much difference for our current purposes. :D

#Comment by Kaldari (talk | contribs)   00:55, 23 June 2011

Good point. How does this look: r90642.

Status & tagging log