https://bugzilla.wikimedia.org/show_bug.cgi?id=23136

--- Comment #12 from Ilmari Karonen <[email protected]> 2010-04-13 16:48:31 UTC 
---
Hadn't thought of that. :(  I guess one way to work around the issue would be
to _tell_ GlobalUsage which shared repos each wiki is using (and in what
order), either through an explicit config variable or simply by recording that
information in a separate table while we update the existing globalimagelinks
table.  Although then the extension would also have to query local image tables
for existence checks, which could be a performance killer... unless we saved
that information in a global table too...

Yeah, that could work.  We'd need three global tables, say: globalimagelinks,
globalimages and globalimagerepos.  The globalimages table would just store
existence data, basically two columns (wiki ID and file name).  The
globalimagerepos would store the filerepo search order for each wiki (three
columns: wiki ID, repo ID and sequence number).  Then a query to find all uses
of a file would look something like:

 SELECT gil_wiki, gil_namespace_text, gil_title
   FROM globalimagelinks, globalimagerepos AS repo1
  WHERE gil_image = ?
    AND repo1.gir_wiki = gil_wiki
    AND repo1.gir_repo = ? 
    AND NOT EXISTS (
        SELECT 1 FROM globalimages, globalimagerepos AS repo2
         WHERE repo2.gir_wiki = repo1.gir_wiki
           AND repo2.gir_priority < repo1.gir_priority
           AND gi_repo = repo2.gir_repo
           AND gi_image = gil_image )

The same could be done without subqueries, using multiple queries and some
client-side processing instead, like this:

1. Find repos where the file exists:

 SELECT gi_repo FROM globalimages WHERE gi_image = ?

2. Find wikis where the file is used:

 SELECT DISTINCT gil_wiki FROM globalimagelinks WHERE gil_image = ?

3. Combine to get list of repos that could provide the file for each wiki:

 SELECT gir_wiki, gir_repo, gir_priority FROM globalimagerepos
  WHERE gir_repo IN (?) AND gir_wiki IN (?)
  ORDER BY gir_wiki, gir_priority

4. Filter out wikis where the current repo is not listed first in the result of
the previous query.

5. Finally get list of uses on the remaining wikis:

 SELECT gil_wiki, gil_namespace_text, gil_title FROM globalimagelinks
  WHERE gil_image = ? AND gil_wiki IN (?)

Hmm, looks nice.  Now someone just needs to code it. :)

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to