Code Monkey home page Code Monkey logo

ancestry's Introduction

Greetings, my friend! ๐Ÿ‘‹

My name is Zven Wang and I am Software Developer based in Beijing.

Developing software since 2011, went from Python to Ruby and React until landing on Elixir and a particular interested for distributed scalable systems and computational logic.

Technologies I love:

  • EventSourcing and CQRS in Elixir
  • Expert systems
  • DSL and parsers built in Elixir/Erlang
  • Phoenix framework
  • Javascript and React
  • gRPC
  • Ruby

ancestry's People

Contributors

dependabot-preview[bot] avatar rafaeliga avatar zven21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ancestry's Issues

`arrange` n + 1 problem

  def arrange(record, _opts, module) do
    case module.has_children?(record) do
      true ->
        Map.merge(record, %{children: do_build_children(record, module)})

      false ->
        record
    end
  end

  defp do_build_children(record, module) do
    record
    |> module.children()
    |> Enum.map(fn x ->
      case module.has_children?(x) do
        true ->
          Map.merge(x, %{children: do_build_children(x, module)})

        false ->
          x
      end
    end)
  end

If a record has 100 children but no grandchildren, We will hit the database 101 times, if every child has 100 children, we will hit the database more than 10000 times, the cost is huge.

Descendants query

The like statement is not accurate, example if id of the record is 1 it will find all subrecord having an ancestry of 10.., 100...

# https://github.com/zven21/ancestry/blob/master/lib/ancestry.ex#L265
query =
  from(
    u in unquote(module),
    where:
      fragment(
        unquote("#{opts[:ancestry_column]} LIKE ?"),
        ^"#{query_string}%"
      )
  )

A quick fix could be something like

query =
  from(
    u in unquote(module),
    where: fragment("#{opts[:ancestry_column]} = ?", "#{query_string}") or
      fragment(
        unquote("#{opts[:ancestry_column]} LIKE ?"),
        ^"#{query_string}/%"
      )
  )

Provide safe version of Module.delete/1 function

Right now, Ancestry.Repo.delete/3 breaks convention by using the unsafe Repo.delete!/2.

Please, provide an alternate version of the function that uses Repo.delete/2 instead. Also, rename the current function to reflect the convention.

This "safe" version of this function, should probably accept and pass on the optional opts keyword list which allows us to treat exceptional cases like :stale_error_field.

category = Repo.get!(Category, id)

# This could be replaced with an exclusion happening in another process or request
Repo.delete!(category) 

# throws unexpected "** (Ecto.StaleEntryError) attempted to delete a stale struct:"
Category.delete(category)

If the struct has been removed from db prior to call, Ecto.StaleEntryError will be raised.

Since by the documentation, this is the default behavior. Ancestry.Repo.delete/3, should either treat the exclusion process completely (and safely) or provide an API that allows it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.