Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Multiple items with same name from different providers #448

Merged
merged 11 commits into from
Jul 27, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions asab/library/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

L = logging.getLogger(__name__)


#


Expand Down Expand Up @@ -79,17 +80,14 @@ def __init__(self, app, service_name, paths=None):
self._create_library(path)
app.PubSub.subscribe("Application.tick/60!", self.on_tick)


async def finalize(self, app):
while len(self.Libraries) > 0:
lib = self.Libraries.pop(-1)
await lib.finalize(self.App)


async def on_tick(self, message_type):
await self._read_disabled()


def _create_library(self, path):
library_provider = None
if path.startswith('zk://') or path.startswith('zookeeeper://'):
Expand Down Expand Up @@ -118,7 +116,6 @@ def _create_library(self, path):

self.Libraries.append(library_provider)


def is_ready(self):
"""
It checks if all the libraries are ready.
Expand All @@ -134,7 +131,6 @@ def is_ready(self):
True
)


async def _set_ready(self, provider):
if len(self.Libraries) == 0:
return
Expand All @@ -149,8 +145,6 @@ async def _set_ready(self, provider):
L.log(LOG_NOTICE, "is NOT ready.", struct_data={'name': self.Name})
self.App.PubSub.publish("Library.not_ready!", self)



async def read(self, path: str, tenant: str = None) -> typing.IO:
"""
Read the content of the library item specified by `path`.
Expand Down Expand Up @@ -188,7 +182,6 @@ async def read(self, path: str, tenant: str = None) -> typing.IO:

return None


async def list(self, path="/", tenant=None, recursive=False) -> list:
"""
List the directory of the library specified by the path.
Expand Down Expand Up @@ -236,10 +229,9 @@ async def list(self, path="/", tenant=None, recursive=False) -> list:
child_items = await self._list(item.name, tenant, providers=item.providers)
items.extend(child_items)
recitems.extend(child_items)

print(items)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print

return items


async def _list(self, path, tenant, providers):
# Execute the list query in all providers in-parallel

Expand All @@ -260,33 +252,28 @@ async def _list(self, path, tenant, providers):
continue

for item in ress:

item.disabled = self.check_disabled(item.name, tenant=tenant)

# If the item already exists, merge it
# If the item already exists, merge or override it
pitem = uniq.get(item.name)
if pitem is not None:
pitem = uniq[item.name]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep pitem = uniq.get(item.name) and test for a None ... it does the same with the half of the cost.

if pitem.type == 'dir' and item.type == 'dir':
# Directories are joined
pitem.providers.extend(item.providers)

elif pitem.type == 'item':
for i, provider in enumerate(providers):
if provider in item.providers:
index = i
break
pitem.override = index
# Other item types are skipped
else:
continue

uniq[item.name] = item
items.append(item)

# Other item types are skipped
else:
uniq[item.name] = item
items.append(item)
items.sort(key=lambda x: x.name)
return items


async def _read_disabled(self):
# `.disabled.yaml` is read from the first configured library
# It is applied on all libraries in the configuration.
Expand All @@ -305,7 +292,6 @@ async def _read_disabled(self):
self.Disabled = {}
L.exception("Failed to parse '/.disabled.yaml'")


def check_disabled(self, path, tenant=None):
"""
If the item is disabled for everybody, or if the item is disabled for the specified tenant, then
Expand All @@ -330,7 +316,6 @@ def check_disabled(self, path, tenant=None):

return False


async def export(self, path="/", tenant=None, remove_path=False) -> typing.IO:
"""
It takes a path, and returns a file-like object containing a gzipped tar archive of the library contents of
Expand Down Expand Up @@ -385,7 +370,6 @@ async def export(self, path="/", tenant=None, remove_path=False) -> typing.IO:
fileobj.seek(0)
return fileobj


async def subscribe(self, paths):
"""
It subscribes to the changes in the library
Expand Down