-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Allow describing an index from a given Type
.
#525
Closed
Closed
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
9cbde32
Use System.Text.Json as the default serializer (#504)
sebastienros 263f1d4
remake DescribeContext<>.For
hyzx86 8fa1f8e
fix UnitTest
hyzx86 cc9cc7e
Update README.md
hyzx86 c6c65cd
Update README.md
hyzx86 d4645fa
Avoid InvalidCastException
2fd4d5b
fix type cache clear
23f9c6b
Update README.md
hyzx86 25f4198
clear code style
e373ca0
Merge branch 'dynamicIndexType' of https://github.com/hyzx86/yessql i…
482ed90
Update PropertyIndex.cs
hyzx86 f850380
Simplify and Cleanup
MikeAlhayek 86d4302
Moving the test. Test should fail MySQL for verification.
MikeAlhayek 74936c1
Fix MySQL error
MikeAlhayek 2c69da9
Last tewaks
MikeAlhayek 144d363
If the same name type is already cached, it should be removed from th…
hyzx86 fbabfc5
add Dynamic Type UnitTest
hyzx86 1d5e8a6
validate index type instance
hyzx86 e83d236
remove error check
hyzx86 5371cd1
Emulating the usage scenario in OrchardCore, the store may be initial…
hyzx86 5df8f36
update unit test
hyzx86 df795ab
add IndexTypeCacheProvider
hyzx86 f74cc3e
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 355b69a
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 6122ff4
Update test/YesSql.Tests/Indexes/PropertyIndex.cs
hyzx86 135d110
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 5ee8f86
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 c500f20
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 b074891
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 10cdf25
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 7c18fb9
Update test/YesSql.Tests/Indexes/DynamicTypeGeneratorSample.cs
hyzx86 a52b5a4
Update test/YesSql.Tests/CoreTests.cs
hyzx86 c213254
Update src/YesSql.Abstractions/Indexes/DescribeContext.cs
hyzx86 01d217f
fix code format
hyzx86 e458a98
use vitrual methods instead Interface
hyzx86 554794d
use session.RegisterIndexes to instead store.RegisterIndexes<Property…
hyzx86 b945de0
Update test/YesSql.Tests/CoreTests.cs
hyzx86 be8d8f3
Update src/YesSql.Core/Commands/IndexCommand.cs
hyzx86 ebc0b32
Update src/YesSql.Abstractions/Indexes/IndexTypeCacheProvider.cs
hyzx86 bc1d2e7
Update src/YesSql.Abstractions/Indexes/IndexTypeCacheProvider.cs
hyzx86 72002c8
Update src/YesSql.Abstractions/Indexes/DescribeContext.cs
hyzx86 16acf5e
Update src/YesSql.Abstractions/IStore.cs
hyzx86 212a333
add UpdateTypeCache Sample
hyzx86 c40413d
Merge branch 'dynamicIndexType' of https://github.com/hyzx86/yessql i…
hyzx86 b0bf2ef
update default index cache
d5429ea
Restoring the test code
cd0928a
rename
784b81c
update unit test
88d1a56
Merge branch 'main' into release/5.0
MikeAlhayek ac2d719
merg from 5.x
hyzx86 8e31c26
Merge branch 'dynamicIndexType' of https://github.com/hyzx86/yessql i…
hyzx86 2b836e8
Merge remote-tracking branch 'origin/main' into dynamicIndexType
hyzx86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using YesSql.Serialization; | ||
|
||
namespace YesSql.Indexes | ||
{ | ||
public class IndexTypeCacheProvider | ||
{ | ||
private static readonly ConcurrentDictionary<PropertyInfo, PropertyInfoAccessor> PropertyAccessors = new(); | ||
private static readonly ConcurrentDictionary<string, PropertyInfo[]> TypeProperties = new(); | ||
|
||
public virtual PropertyInfoAccessor GetPropertyAccessor(PropertyInfo property) => PropertyAccessors.GetOrAdd(property, p => new PropertyInfoAccessor(p)); | ||
|
||
public virtual PropertyInfo[] GetTypeProperties(Type type) | ||
{ | ||
if (TypeProperties.TryGetValue(type.FullName, out var pis)) | ||
{ | ||
return pis; | ||
} | ||
|
||
var properties = type.GetProperties().Where(IsWriteable).ToArray(); | ||
TypeProperties[type.FullName] = properties; | ||
|
||
return properties; | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public virtual void UpdateCachedType(Type type) | ||
{ | ||
if (TypeProperties.TryRemove(type.FullName, out var pis)) | ||
{ | ||
foreach (var prop in pis) | ||
{ | ||
PropertyAccessors.TryRemove(prop, out _); | ||
} | ||
} | ||
|
||
var properties = type.GetProperties().Where(IsWriteable).ToArray(); | ||
TypeProperties[type.FullName] = properties; | ||
} | ||
|
||
protected bool IsWriteable(PropertyInfo pi) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MikeAlhayek Because this method is needed for caching in Yessql, I changed the original IIndexTypeCacheProvider to IndexTypeCacheProvider and included some virtual methods |
||
return | ||
pi.Name != nameof(IIndex.Id) && | ||
// don't read DocumentId when on a MapIndex as it might be used to | ||
// read the DocumentId directly from an Index query | ||
pi.Name != "DocumentId" | ||
; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace YesSql.Serialization | ||
{ | ||
public class DefaultContentSerializer : IContentSerializer | ||
{ | ||
private readonly JsonSerializerOptions _options; | ||
|
||
public DefaultContentSerializer() | ||
{ | ||
_options = new(); | ||
_options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; | ||
_options.Converters.Add(UtcDateTimeJsonConverter.Instance); | ||
_options.Converters.Add(DynamicJsonConverter.Instance); | ||
} | ||
|
||
public DefaultContentSerializer(JsonSerializerOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
public object Deserialize(string content, Type type) | ||
{ | ||
return JsonSerializer.Deserialize(content, type, _options); | ||
} | ||
|
||
public string Serialize(object item) | ||
{ | ||
return JsonSerializer.Serialize(item, _options); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MikeAlhayek We need to add it to the
IConfiguration
so that it can be overridden by other implementationsSo I extracted
IndexTypeCacheProvider
into the Abstraction projectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to reply. Because I didn't submit my comments 😢
I always wondered why there was a
Pendding
mark on my reply. I just figured it out.