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

Display the number keys inside each namespace, recursively. (issue #3470) #3481

Merged
merged 3 commits into from Sep 28, 2015

Conversation

dmagliola
Copy link
Contributor

For each namespace, this shows how many keys are inside it, which I find very useful to have a very rough idea of where my Redis memory usage is going, and also a rough idea of what my app is doing with Redis (how many objects of each type are getting cached, things like that).

The implementation is a bit hacky, because NamespaceItem::getDisplayName is being used both for actual display, and as the key in hash tables that list child namespaces. To get around this, I added a getOriginalDisplayName method to use for the hash key. I admit the name could've probably been a bit better, but I don't know the codebase well enough to pick a better one (i'd be happy to rename to whatever you'd like to see).

This also required a couple of casts, hope those are OK.

If you think this is a good idea to incorporate, but don't like how it's implemented, i'll be happy to improve it / change it. I'd love to see this on the official app.

Thanks!
Daniel

@uglide
Copy link
Collaborator

uglide commented Sep 28, 2015

Hello @dmagliola

Code looks good but need some improvements:

  1. Rename NamespaceItem::getOriginalDisplayName -> NamespaceItem::getName
  2. Modify signature of method TreeItem::childCount virtual uint childCount(bool recursive = false) const = 0;
  3. Update signatures in child classes:
    3.1. DatabaseItem
    3.2. KeyItem
    3.3. NamespaceItem
    3.4. ServerItem
  4. Remove NamespaceItem::descendantCount method and update NamespaceItem::childCount method:
 uint NamespaceItem::childCount(bool recursive) const
 {
    if (!recursive)
      return m_childItems.size();

    uint count = 0;
    for (auto item : m_childItems)
      count += item.childCount(true);

    return count;
 }

It will remove usage of RTTI and improve performance.

Please fix mentioned issues and I will merge this pull request. Thank you!

@dmagliola
Copy link
Contributor Author

Thank you for reviewing this so quickly!
I like your changes, however, the childCount method doesn't work as you defined it, because childCount returns 0 for KeyItem, so the childCount is always 0 if recursive (you end up summing long strings of zeroes, basically). And if keyItem returns 1 on KeyItem::childCount, that pretty much destroys the tree.

It does work, however, if you define KeyItem::childCount, as such:

uint KeyItem::childCount(bool recursive) const
{
    return (uint) (recursive ? 1 : 0);
}

Although that's a bit weird... Of course that'd have a big comment explaining what you're doing, but it feels hacky.

Up to you, I have very little experience with Qt or the codebase, so you tell me how you'd prefer this.

@uglide
Copy link
Collaborator

uglide commented Sep 28, 2015

@dmagliola Yes, I have missed this. But it's easy to solve this problem without any workarounds, just add virtual bool supportChildItems() { return true; } to TreeItem class, add virtual bool supportChildItems() { return false; } to KeyItem class and update code of NamespaceItem::childCount :

 uint NamespaceItem::childCount(bool recursive) const
 {
    if (!recursive)
      return m_childItems.size();

    uint count = 0;
    for (auto item : m_childItems) {
      if (item.supportChildItems()) {
        count += item.childCount(true);
      } else {
        count += 1;
      }
    }
    return count;
 }

In most cases it's better to extend interface instead of adding hardcode for concreate types.

…ildCount to accept a "recursive" parameter for all TreeItems.
@dmagliola
Copy link
Contributor Author

I like that much more now! :-)
Done!
Let me know if that's ok

uglide added a commit that referenced this pull request Sep 28, 2015
Display the number keys inside each namespace, recursively. (issue #3470)
@uglide uglide merged commit 2d10440 into RedisInsight:0.8.0 Sep 28, 2015
@uglide
Copy link
Collaborator

uglide commented Sep 28, 2015

Merged! Thanks! Keep doing great improvements in RDM ;)

@dmagliola
Copy link
Contributor Author

Thank you! My ability to do C++ and Qt is very, very limited, so not sure how much i'll be able to contribute, but I use RDM all day, and constantly come up with little tweaks and improbements, so now that I can actually compile, i'll try to implement them!
Thanks!

@uglide
Copy link
Collaborator

uglide commented Sep 28, 2015

@dmagliola Large part of RDM is coded in JS/QML which is very easy to understand and modify (example is Value editor)
Also feel free to ping me via email or gitter if you need help or if you have any questions about codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants