r92269 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92268‎ | r92269 | r92270 >
Date:18:33, 15 July 2011
Author:raindrift
Status:ok (Comments)
Tags:
Comment:
No longer using the content hash as a file key. This solves a concurrency problem when multiple people use the same account to upload from the same set of files. Each stashed file is now a unique and beautiful snowflake, and the content-based deduping that comes at the end of the process can sort it out.
Modified paths:
  • /trunk/phase3/includes/upload/UploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadStash.php
@@ -17,7 +17,7 @@
1818 class UploadStash {
1919
2020 // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg)
21 - const KEY_FORMAT_REGEX = '/^[\w-]+\.\w*$/';
 21+ const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/';
2222
2323 // When a given stashed file can't be loaded, wait for the slaves to catch up. If they're more than MAX_LAG
2424 // behind, throw an exception instead. (at what point is broken better than slow?)
@@ -184,7 +184,6 @@
185185 throw new UploadStashBadPathException( "path doesn't exist" );
186186 }
187187 $fileProps = File::getPropsFromPath( $path );
188 -
189188 wfDebug( __METHOD__ . " stashing file at '$path'\n" );
190189
191190 // we will be initializing from some tmpnam files that don't have extensions.
@@ -198,10 +197,17 @@
199198 $path = $pathWithGoodExtension;
200199 }
201200
202 - // If no key was supplied, use content hash. Also has the nice property of collapsing multiple identical files
203 - // uploaded this session, which could happen if uploads had failed.
 201+ // If no key was supplied, make one. a mysql insertid would be totally reasonable here, except
 202+ // that some users of this function might expect to supply the key instead of using the generated one.
204203 if ( is_null( $key ) ) {
205 - $key = $fileProps['sha1'] . "." . $extension;
 204+ // some things that when combined will make a suitably unique key.
 205+ // see: http://www.jwz.org/doc/mid.html
 206+ list ($usec, $sec) = explode( ' ', microtime() );
 207+ $usec = substr($usec, 2);
 208+ $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' .
 209+ wfBaseConvert( mt_rand(), 10, 36 ) . '.'.
 210+ $this->userId . '.' .
 211+ $extension;
206212 }
207213
208214 $this->fileProps[$key] = $fileProps;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92081Added us_status column for future expansion re Bryan's suggestion...raindrift19:08, 13 July 2011

Comments

#Comment by Raindrift (talk | contribs)   23:40, 19 July 2011

Follow-up: r92081

Status & tagging log