Skip to content

Commit

Permalink
remove anycast, optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nero committed Jun 26, 2024
1 parent aba16fb commit 1f8cb70
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions Application/Application.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<ClInclude Include="BaseQuery.h" />
<ClInclude Include="BaseCommand.h" />
<ClInclude Include="BaseQueryV2.h" />
<ClInclude Include="BaseQueryV3.h" />
<ClInclude Include="ChatParticipantModel.h" />
<ClInclude Include="ChatParticipantService.h" />
<ClInclude Include="ChatRoomModel.h" />
Expand Down
3 changes: 3 additions & 0 deletions Application/Application.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<ClInclude Include="MediaMessageModel.h">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="BaseQueryV3.h">
<Filter>Header Files\Common\ORM</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ApplicationUserServices.cpp">
Expand Down
41 changes: 17 additions & 24 deletions Application/BaseQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_items_future = std::async(std::launch::async, &BaseQuery::GetAll<inner_elem_type>, this, table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
auto inner_items = inner_items_future.get();
(item.get()->*(D).pointer) = inner_items_future.get();
#else
auto inner_items = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
(item.get()->*(D).pointer) = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_items);
}
}
else if constexpr (is_shared_ptr_v<type>)
Expand All @@ -91,11 +90,11 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_item_future = std::async(std::launch::async, &BaseQuery::GetSingle<inner_elem_type>, this, PKEY " = '" + id + "'", includes);
auto inner_item = inner_item_future.get();
(item.get()->*(D).pointer) = inner_item_future.get();
#else
auto inner_item = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
(item.get()->*(D).pointer) = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_item);

}
}
}
Expand Down Expand Up @@ -162,11 +161,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_items_future = std::async(std::launch::async, &BaseQuery::GetAll<inner_elem_type>, this, table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
auto inner_items(inner_items_future.get());
(item.get()->*(D).pointer) = (inner_items_future.get());
#else
auto inner_items = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
(item.get()->*(D).pointer) = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_items);
}
}
else if constexpr (is_shared_ptr_v<type>)
Expand All @@ -181,11 +179,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_item_future = std::async(std::launch::async, &BaseQuery::GetSingle<inner_elem_type>, this, PKEY " = '" + id + "'", includes);
auto inner_item = inner_item_future.get();
(item.get()->*(D).pointer) = inner_item_future.get();
#else
auto inner_item = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
(item.get()->*(D).pointer) = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_item);
}
}

Expand Down Expand Up @@ -302,11 +299,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_items_future = std::async(std::launch::async, &BaseQuery::GetAll<inner_elem_type>, this, table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
auto inner_items = inner_items_future.get();
(item.get()->*(D).pointer) = inner_items_future.get();
#else
auto inner_items = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
(item.get()->*(D).pointer) = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_items);
}
}
else if constexpr (is_shared_ptr_v<type>)
Expand All @@ -321,11 +317,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_ptr_item_future = std::async(std::launch::async, &BaseQuery::GetSingle<inner_elem_type>, this, PKEY " = '" + id + "'", includes);
auto inner_ptr_item = inner_ptr_item_future.get();
(item.get()->*(D).pointer) = inner_ptr_item_future.get();
#else
auto inner_ptr_item = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
(item.get()->*(D).pointer) = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_ptr_item);
}

}
Expand Down Expand Up @@ -400,11 +395,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_items_future = std::async(std::launch::async, &BaseQuery::GetAll<inner_elem_type>, this, table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes_copy);
auto inner_items = inner_items_future.get();
(item.get()->*(D).pointer) = inner_items_future.get();
#else
auto inner_items = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
(item.get()->*(D).pointer) = GetAll<inner_elem_type>(table_name + "Id = '" + client->GetStringResult(PKEY) + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_items);
}
}
else if constexpr (is_shared_ptr_v<type>)
Expand All @@ -419,11 +413,10 @@ class APPLICATION_API BaseQuery
includes_copy.erase(std::remove_if(includes_copy.begin(), includes_copy.end(), [&](std::string s) { return s == D.name; }), includes_copy.end());
#ifdef ASYNC
auto inner_item_future = std::async(std::launch::async, &BaseQuery::GetSingle<inner_elem_type>, this, PKEY " = '" + id + "'", includes);
auto inner_item = inner_item_future.get();
(item.get()->*(D).pointer) = inner_item_future.get();
#else
auto inner_item = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
(item.get()->*(D).pointer) = GetSingle<inner_elem_type>(PKEY " = '" + id + "'", includes);
#endif // ASYNC
(item.get()->*(D).pointer) = std::any_cast<type>(inner_item);
}
}

Expand Down
28 changes: 28 additions & 0 deletions Application/BaseQueryV3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <type_traits>
#include <BaseEntity.h>

//TODO: Implement Query class

template <typename T, typename = std::is_base_of<BaseEntity, T>::type>
class Query
{
public:
Query();
~Query();
Query& Where(std::string where)
{
_where = where;
return *this;
}

template<typename F>
Query& Include(F f)
{
_includes.push_back(typeid(f()).name());
return *this;
}

private:
std::string _command;
};

0 comments on commit 1f8cb70

Please sign in to comment.