Page MenuHomePhabricator

PrefetchingTermLookup Service returns a doubly nested Term Lookup
Open, LowPublic

Description

Currently - and possibly due to an oversight - the PrefetchingTermLookup returns a Lookup class with an unnecessarily doubly nested structure as seen below, for every source that contains more than one type.

Questions:

  • Should the lookup collect all types into a more flat structure, to prevent duplication and nesting of lookup instances? If so, then this task should aim to achieve that, otherwise, the task can be declined.

Example:

["lookups":"Wikibase\DataAccess\ByTypeDispatchingPrefetchingTermLookup":private]=>
  array(2) {
    ["item"]=> ByTypeDispatchingPrefetchingTermLookup) {
      ["lookups":"ByTypeDispatchingPrefetchingTermLookup":private] =>
      array(2) {
        ["item"] => FakePrefetchingTermLookup {
          ["buffer":"FakePrefetchingTermLookup":private] => NULL
        }
        ["property"] => FakePrefetchingTermLookup {
          ["buffer":"FakePrefetchingTermLookup":private] => NULL
        }
      }
      ["defaultLookup":"ByTypeDispatchingPrefetchingTermLookup":private] =>
      NullPrefetchingTermLookup) {}
    }
    ["property"] => ByTypeDispatchingPrefetchingTermLookup) {
      ["lookups":"ByTypeDispatchingPrefetchingTermLookup":private] =>
      array(2) {
        ["item"] => FakePrefetchingTermLookup {
          ["buffer":"FakePrefetchingTermLookup":private] => NULL
        }
        ["property"] => FakePrefetchingTermLookup {
          ["buffer":"FakePrefetchingTermLookup":private] => NULL
        }
      }
      ["defaultLookup":"ByTypeDispatchingPrefetchingTermLookup":private] =>
      NullPrefetchingTermLookup) {}
    }
  }
  ["defaultLookup":"ByTypeDispatchingPrefetchingTermLookup":private] => NULL

Event Timeline

So the top level of dispatching happens in https://github.com/wikimedia/Wikibase/blob/4eefb25d289d928f81230f306570a1a575a7ceba/data-access/src/MultipleEntitySourceServices.php#L95-L108
This currently gets a PrefetchingTermLookup for the whole entity source, rather than for a specific entity type from the entity source.
It appears this is why things get wrapped twice.

Although appearing a bit odd this should end up doing the right thing and shouldn't have much overhead.

A "fix" would be to modify https://github.com/wikimedia/Wikibase/blob/4eefb25d289d928f81230f306570a1a575a7ceba/data-access/src/SingleEntitySourceServices.php#L346-L377 / SingleEntitySourceServices to allow retrieval of services like this specific to one of the entity types that they are the source for.

Cool, thanks for the reply, yeah the "fix" shouldn't be too much trouble, I just wasn't sure if this was intentional, or even worth spending time on, since, as you say, the resulting lookup would act exactly the same either way. I can take care of it after T277314 is fully merged.