Repository: iterative/dvc

Issue:
DVC pull takes a long time from gStorage since 2.34.0
# Bug Report

Hi i have updated to 2.34.3 this morning and now my dvc pull command is taking a very long time.

```
$> python3 -m dvc --version && time python3 -m dvc pull data.dvc 
2.33.2
Everything is up to date.                                                                                                                                                                                                                                     

real	0m2,898s
user	0m2,746s
sys	0m0,116s

$> python3 -m dvc --version && time python3 -m dvc pull data.dvc 
2.34.3
Everything is up to date.                                                                                                                                                                                                                                     

real	1m17,122s
user	1m1,540s
sys	0m3,196s
```

My remote is on gStorage and i'm trying to pull a simple file that is already present.

I have then install 2.33.2 issue was no more present then bumping to 2.34.0 issue appears.

I have did a git bissect and this point to :

```
3891e81bddd3eabf9124f3b246fbe8d3181b0c48 is the first bad commit
commit 3891e81bddd3eabf9124f3b246fbe8d3181b0c48
Author: Peter Rowlands <peter@pmrowla.com>
Date:   Fri Nov 4 18:03:44 2022 +0900

    index: load dir entries before generating target views

 dvc/repo/index.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
```



Discussion:
^ @pmrowla for your information 
@clementperon can you run `dvc doctor` and post the output? Also, does your repo contain any imports (.dvc files created with `dvc import-url`)?
@pmrowla 
```
$>  dvc doctor
DVC version: 2.35.1 (pip)
---------------------------------
Platform: Python 3.10.6 on Linux-6.0.6-76060006-generic-x86_64-with-glibc2.35
Subprojects:
	dvc_data = 0.28.0
	dvc_objects = 0.14.0
	dvc_render = 0.0.14
	dvc_task = 0.1.6
	dvclive = 1.0.1
	scmrepo = 0.1.3
Supports:
	gs (gcsfs = 2022.11.0),
	http (aiohttp = 3.8.1, aiohttp-retry = 2.8.3),
	https (aiohttp = 3.8.1, aiohttp-retry = 2.8.3),
	ssh (sshfs = 2022.6.0)
Cache types: hardlink, symlink
Cache directory: ext4 on /dev/nvme0n1p7
Caches: local
Remotes: gs
Workspace directory: ext4 on /dev/nvme0n1p7
Repo: dvc, git
```
> Also, does your repo contain any imports (.dvc files created with dvc import-url)

I would say no but i'm not sure the dvc file i'm trying to pull looks like this 
```
outs:
- md5: 94a941663a664a3ad0624404ba3115f9
  size: 46637
  path: mydata
  remote: software
```


Resolving patch:
diff --git a/dvc/repo/index.py b/dvc/repo/index.py
--- a/dvc/repo/index.py
+++ b/dvc/repo/index.py
@@ -11,6 +11,7 @@
     Optional,
     Set,
     Tuple,
+    Union,
 )
 
 from funcy import cached_property, nullcontext
@@ -429,10 +430,10 @@ def _data_prefixes(self) -> Dict[str, "_DataPrefixes"]:
         return prefixes
 
     @cached_property
-    def data(self) -> "Dict[str, DataIndexView]":
+    def data(self) -> Dict[str, Union["DataIndex", "DataIndexView"]]:
         from functools import partial
 
-        from dvc_data.index import view
+        from dvc_data.index import DataIndex, view
 
         def key_filter(workspace: str, key: "DataIndexKey"):
             try:
@@ -444,10 +445,15 @@ def key_filter(workspace: str, key: "DataIndexKey"):
             except KeyError:
                 return False
 
-        data = {}
+        data: Dict[str, Union["DataIndex", "DataIndexView"]] = {}
         for workspace, data_index in self._index.data.items():
-            data_index.load()
-            data[workspace] = view(data_index, partial(key_filter, workspace))
+            if self._stages:
+                data_index.load()
+                data[workspace] = view(
+                    data_index, partial(key_filter, workspace)
+                )
+            else:
+                data[workspace] = DataIndex()
         return data
 
 


Test patch: