-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RFC: let data source find objects
- Loading branch information
1 parent
7641a78
commit f2edd72
Showing
1 changed file
with
41 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
= Let data source find objects | ||
:start_date: 2016-01-03 | ||
:rfc_issue: (leave this empty) | ||
:nanoc_issue: (leave this empty) | ||
|
||
== Summary | ||
|
||
Move the responsibility of finding items and layouts to the data sources, so that they can implement efficient methods of finding items (e.g. by using globs properly). | ||
|
||
== Motivation | ||
|
||
The current algorithm for finding items and layouts has a time complexity of O(n) in the number of items/layouts. By pushing down the responsibility for finding items and layouts into the data sources, these data sources can implement a domain-specific, efficient algorithm for finding items (e.g. using globs in a filesystem data source, or indexes in a SQL database). | ||
|
||
Additionally, this brings Nanoc a step closer to not requiring items to be loaded into memory at all times. This is currently required in order to do the searching. | ||
|
||
== Detailed design | ||
|
||
Data sources will get the following new methods: | ||
|
||
* `#item_matching(glob)`: return a single item matching the given glob | ||
* `#items_matching(glob)`: return a collection of items matching the given glob | ||
* `#layout_matching(glob)`: return a single layout matching the given glob | ||
* `#layouts_matching(glob)`: return a collection of layouts matching the given glob | ||
|
||
All of these methods are optional. When not implemented, their default behavior will be to fall back to `#items` or `#layouts` and use the current (inefficient) searching algorithm. | ||
|
||
Item and layout collections will gain access to the data sources. When finding an item or layout given a glob, the item/layout collection will query all data sources. | ||
|
||
== Drawbacks | ||
|
||
(none) | ||
|
||
== Alternatives | ||
|
||
* Modify the current in-memory algorithm to use globs efficiently. This might require us to re-implement the algorithm of finding objects using globs, rather than reusing what already exists. | ||
|
||
== Unresolved questions | ||
|
||
The preprocessor makes this approach quite a bit harder, because it is capable of creating, removing and modifying items and layouts. It might also require all items and layouts (or at least references to them) to be loaded into memory. | ||
|
||
An idea to help with this would be to create a specific preprocessor data source, along with some structure that describes which items/layouts have been deleted; modified items/layouts are considered as deleted and by this structure, and will be part of this preprocessor data source. |